Skip to content

Commit 67f2f43

Browse files
committed
fix: checkout page now compatible with pseudo slots.
1 parent fe6f02e commit 67f2f43

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

apps/web/src/components/Checkout/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const schema: Zod.Schema<TxTypePayload> = zod.union([
77
zod.object({
88
type: zod.literal("paid-lesson"),
99
tutorId: zod.coerce.number().int().positive(),
10-
slotId: zod.coerce.number().int().positive(),
10+
slotId: zod.coerce.number().int(),
1111
start: zod.string().datetime(),
1212
duration: zod.coerce.number().int().positive(),
1313
}),

services/server/src/handlers/lesson.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,15 @@ async function createWithCard(req: Request, res: Response, next: NextFunction) {
149149
const phone = await withPhone(user, payload.phone);
150150
if (phone instanceof Error) return next(bad(phone.message));
151151

152+
if (payload.slotId < 0) {
153+
const pseudoSlot = await createPseudoLessonSlot({
154+
tutorId: payload.tutorId,
155+
duration: payload.duration,
156+
start: payload.start,
157+
});
158+
payload.slotId = pseudoSlot.id;
159+
}
160+
152161
const valid = await validateCreateLessonPayload(payload);
153162
if (valid instanceof TutorNotFound) return next(notfound.tutor());
154163
if (valid instanceof SlotNotFound) return next(notfound.slot());
@@ -200,6 +209,15 @@ async function createWithFawryRefNum(
200209
const phone = await withPhone(user, payload.phone);
201210
if (phone instanceof Error) return next(bad(phone.message));
202211

212+
if (payload.slotId < 0) {
213+
const pseudoSlot = await createPseudoLessonSlot({
214+
tutorId: payload.tutorId,
215+
duration: payload.duration,
216+
start: payload.start,
217+
});
218+
payload.slotId = pseudoSlot.id;
219+
}
220+
203221
const valid = await validateCreateLessonPayload(payload);
204222
if (valid instanceof TutorNotFound) return next(notfound.tutor());
205223
if (valid instanceof SlotNotFound) return next(notfound.slot());
@@ -249,6 +267,15 @@ async function createWithEWallet(
249267
const phone = await withPhone(user, payload.phone);
250268
if (phone instanceof Error) return next(bad(phone.message));
251269

270+
if (payload.slotId < 0) {
271+
const pseudoSlot = await createPseudoLessonSlot({
272+
tutorId: payload.tutorId,
273+
duration: payload.duration,
274+
start: payload.start,
275+
});
276+
payload.slotId = pseudoSlot.id;
277+
}
278+
252279
const valid = await validateCreateLessonPayload(payload);
253280
if (valid instanceof TutorNotFound) return next(notfound.tutor());
254281
if (valid instanceof SlotNotFound) return next(notfound.slot());

0 commit comments

Comments
 (0)