diff --git a/src/app/api/shop/getAll/route.ts b/src/app/api/shop/getAll/route.ts index 4aec80cb4..877689811 100644 --- a/src/app/api/shop/getAll/route.ts +++ b/src/app/api/shop/getAll/route.ts @@ -1,5 +1,3 @@ -'use server' - import { apiHandler } from '@/app/api/apiHandler' import { readShops } from '@/services/shop/shop/read' diff --git a/src/app/api/shop/product/barcode/route.ts b/src/app/api/shop/product/barcode/route.ts index f18469cc3..2a38a8784 100644 --- a/src/app/api/shop/product/barcode/route.ts +++ b/src/app/api/shop/product/barcode/route.ts @@ -1,5 +1,3 @@ -'use server' - import { apiHandler } from '@/app/api/apiHandler' import { readProductByBarCode } from '@/services/shop/product/read' diff --git a/src/app/api/shop/purchase/createByStudentCard/route.ts b/src/app/api/shop/purchase/createByStudentCard/route.ts index f249831db..74f64997a 100644 --- a/src/app/api/shop/purchase/createByStudentCard/route.ts +++ b/src/app/api/shop/purchase/createByStudentCard/route.ts @@ -1,4 +1,3 @@ -'use server' import { apiHandler } from '@/app/api/apiHandler' import { createPurchaseByStudentCard } from '@/services/shop/purchase/create' diff --git a/src/app/api/users/connectStudentCard/route.ts b/src/app/api/users/connectStudentCard/route.ts index 9155235c2..78f60fb12 100644 --- a/src/app/api/users/connectStudentCard/route.ts +++ b/src/app/api/users/connectStudentCard/route.ts @@ -1,5 +1,3 @@ -'use server' - import { apiHandler } from '@/api/apiHandler' import { connectStudentCard } from '@/services/users/update' diff --git a/src/app/api/users/getWithBalance/[studentCard]/route.ts b/src/app/api/users/getWithBalance/[studentCard]/route.ts new file mode 100644 index 000000000..8c9bcb9d2 --- /dev/null +++ b/src/app/api/users/getWithBalance/[studentCard]/route.ts @@ -0,0 +1,10 @@ +import { apiHandler } from '@/api/apiHandler' +import { readUserWithBalance } from '@/services/users/read' + + +export const GET = apiHandler({ + params: (rawparams: { studentCard: string }) => ({ + studentCard: rawparams.studentCard, + }), + serviceMethod: readUserWithBalance, +}) diff --git a/src/services/shop/purchase/create.ts b/src/services/shop/purchase/create.ts index 1db8e03f7..48f56c5bd 100644 --- a/src/services/shop/purchase/create.ts +++ b/src/services/shop/purchase/create.ts @@ -85,7 +85,7 @@ export const createPurchaseByStudentCard = ServiceMethod({ // TODO: Return remaining balance in account return { - remainingBalance: 15100, + remainingBalance: 191900, user, productList, } diff --git a/src/services/users/read.ts b/src/services/users/read.ts index 08ba9f609..60d38a27f 100644 --- a/src/services/users/read.ts +++ b/src/services/users/read.ts @@ -142,6 +142,31 @@ export async function readUserOrNull(where: readUserWhere): Promise return await prismaCall(() => prisma.user.findFirst({ where })) } +export const readUserWithBalance = ServiceMethod({ + auther: ({ params }) => readUserAuther.dynamicFields({ + username: params.username || '', + }), + paramsSchema: z.object({ + username: z.string().optional(), + id: z.number().optional(), + email: z.string().optional(), + studentCard: z.string().optional(), + }), + method: async ({ prisma: prisma_, params }) => { + const user = await prisma_.user.findFirstOrThrow({ + where: params, + include: { + image: true, + } + }) + + return { + balance: 191900, + user, + } + } +}) + export const readUserProfile = ServiceMethod({ paramsSchema: z.object({ username: z.string(),