continue extracting user controllers out of routes

This commit is contained in:
Aaron William Po
2023-12-06 20:30:11 -05:00
parent 2ff39613cd
commit c7d5c65ffb
31 changed files with 584 additions and 543 deletions

View File

@@ -16,7 +16,7 @@ const getBeerPostsByBeerStyleId = async ({
const beers = await DBClient.instance.beerPost.findMany({
where: { styleId },
take: pageSize,
skip: pageNum * pageSize,
skip: (pageNum - 1) * pageSize,
select: {
id: true,
name: true,

View File

@@ -16,7 +16,7 @@ const getAllBeerPostsByBreweryId = async ({
const beers = await DBClient.instance.beerPost.findMany({
where: { breweryId },
take: pageSize,
skip: pageNum * pageSize,
skip: (pageNum - 1) * pageSize,
select: {
id: true,
name: true,

View File

@@ -16,7 +16,7 @@ const getBeerPostsByPostedById = async ({
const beers = await DBClient.instance.beerPost.findMany({
where: { postedBy: { id: postedById } },
take: pageSize,
skip: pageNum * pageSize,
skip: (pageNum - 1) * pageSize,
select: {
id: true,
name: true,

View File

@@ -0,0 +1,10 @@
import { BaseCreateUserSchema } from './CreateUserValidationSchemas';
const EditUserSchema = BaseCreateUserSchema.pick({
username: true,
email: true,
firstName: true,
lastName: true,
});
export default EditUserSchema;

View File

@@ -0,0 +1,33 @@
import DBClient from '@/prisma/DBClient';
import { z } from 'zod';
import GetUserSchema from './schema/GetUserSchema';
interface UpdateUserProfileByIdParams {
id: string;
data: { bio: string };
}
const updateUserProfileById = async ({ id, data }: UpdateUserProfileByIdParams) => {
const user: z.infer<typeof GetUserSchema> = await DBClient.instance.user.update({
where: { id },
data: { bio: data.bio },
select: {
id: true,
username: true,
email: true,
bio: true,
userAvatar: true,
accountIsVerified: true,
createdAt: true,
firstName: true,
lastName: true,
updatedAt: true,
dateOfBirth: true,
role: true,
},
});
return user;
};
export default updateUserProfileById;