mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 18:52:06 +00:00
continue extracting user controllers out of routes
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
10
src/services/User/schema/EditUserSchema.ts
Normal file
10
src/services/User/schema/EditUserSchema.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { BaseCreateUserSchema } from './CreateUserValidationSchemas';
|
||||
|
||||
const EditUserSchema = BaseCreateUserSchema.pick({
|
||||
username: true,
|
||||
email: true,
|
||||
firstName: true,
|
||||
lastName: true,
|
||||
});
|
||||
|
||||
export default EditUserSchema;
|
||||
33
src/services/User/updateUserProfileById.ts
Normal file
33
src/services/User/updateUserProfileById.ts
Normal 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;
|
||||
Reference in New Issue
Block a user