Skip to content

Commit f694808

Browse files
committed
refactor: use tutor price instead of static platform price
1 parent 73c18f0 commit f694808

File tree

8 files changed

+38
-4
lines changed

8 files changed

+38
-4
lines changed

packages/headless/src/tutor.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ export function useFindTutorActivityScore(id: number | null): {
130130
type IForm = {
131131
bio: string;
132132
about: string;
133+
price: number;
133134
};
134135

135136
export function useIntroduceTutor({
@@ -149,6 +150,7 @@ export function useIntroduceTutor({
149150
return await api.user.update(profile.id, {
150151
bio: fields.bio,
151152
about: fields.about,
153+
price: fields.price,
152154
});
153155
},
154156
[api.user, profile]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { MigrationBuilder } from "node-pg-migrate";
2+
3+
export async function up(pgm: MigrationBuilder): Promise<void> {
4+
pgm.addColumn("tutors", {
5+
price: {
6+
type: "int",
7+
notNull: false,
8+
},
9+
});
10+
}
11+
12+
export async function down(pgm: MigrationBuilder): Promise<void> {
13+
pgm.dropColumn("tutors", "price");
14+
}

packages/models/src/tutors.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ const fullTutorFields: FullTutorFieldsMap = {
5555
thumbnail: tutorColumn("thumbnail"),
5656
notice: tutorColumn("notice"),
5757
activated: tutorColumn("activated"),
58+
price: tutorColumn("price"),
5859
bypass_onboarding: tutorColumn("bypass_onboarding"),
5960
} as const;
6061

@@ -85,6 +86,7 @@ export class Tutors {
8586
.update({
8687
bio: payload.bio,
8788
about: payload.about,
89+
price: payload.price,
8890
video: payload.video,
8991
notice: payload.notice,
9092
thumbnail: payload.thumbnail,
@@ -507,6 +509,7 @@ export class Tutors {
507509
id: row.id,
508510
bio: row.bio,
509511
about: row.about,
512+
price: row.price,
510513
video: row.video,
511514
thumbnail: row.thumbnail,
512515
studioId: row.studio_id,
@@ -543,6 +546,7 @@ export class Tutors {
543546
id: row.id,
544547
bio: row.bio,
545548
about: row.about,
549+
price: row.price,
546550
video: row.video,
547551
thumbnail: row.thumbnail,
548552
studioId: row.studio_id,

packages/types/src/tutor.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export type Self = {
55
id: number;
66
bio: string | null;
77
about: string | null;
8+
price: number | null;
89
video: string | null;
910
studioId: number | null;
1011
thumbnail: string | null;
@@ -74,6 +75,7 @@ export type Row = {
7475
notice: number;
7576
bio: string | null;
7677
about: string | null;
78+
price: number | null;
7779
video: string | null;
7880
role: IUser.Role;
7981
activated: boolean;
@@ -95,6 +97,7 @@ export type TutorMedia = {
9597
export type UpdatePayload = {
9698
bio?: string | null;
9799
about?: string | null;
100+
price?: number | null;
98101
video?: string | null;
99102
thumbnail?: string | null;
100103
studioId?: number | null;

packages/types/src/user.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ export type UpdateApiPayload = {
156156
video?: null;
157157
bio?: string | null;
158158
about?: string | null;
159+
price?: number | null;
159160
phone?: string | null;
160161
city?: City | null;
161162
studioId?: number | null;

packages/utils/src/lesson.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1-
import { ILesson } from "@litespace/types";
1+
import { ILesson, ITutor } from "@litespace/types";
22
import { MINUTES_IN_HOUR, TOTAL_LESSON_HOURLY_RATE } from "@/constants";
33
import { sumBy } from "lodash";
44

55
/**
66
* @param duration {ILesson.Duration}
77
* @returns scaled lesson price
88
*/
9-
export function calculateLessonPrice(duration: ILesson.Duration): number {
10-
return Math.floor((duration / MINUTES_IN_HOUR) * TOTAL_LESSON_HOURLY_RATE);
9+
export function calculateLessonPrice(
10+
duration: ILesson.Duration,
11+
tutor?: ITutor.Self
12+
): number {
13+
return Math.floor(
14+
(duration / MINUTES_IN_HOUR) * (tutor?.price ?? TOTAL_LESSON_HOURLY_RATE)
15+
);
1116
}
1217

1318
export function sumLessonsDuration(lessons: ILesson.Self[]): number {

services/server/src/handlers/user.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ function update(_: ApiContext) {
276276
video,
277277
bio,
278278
about,
279+
price,
279280
notice,
280281
studioId,
281282
phone,
@@ -382,6 +383,7 @@ function update(_: ApiContext) {
382383
const updateTutorPayload: ITutor.UpdatePayload = {
383384
bio,
384385
about,
386+
price,
385387
notice,
386388
studioId,
387389
video,

services/server/src/lib/lesson.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,10 +374,13 @@ export async function createLesson({
374374
slotId,
375375
start,
376376
duration,
377+
price,
377378
});
378379
if (tutor instanceof Error) return tutor;
379380

380-
const price = isTutorManager(tutor) ? 0 : calculateLessonPrice(duration);
381+
const price = isTutorManager(tutor)
382+
? 0
383+
: calculateLessonPrice(duration, tutor.price);
381384

382385
// Create the lesson with its associated room if it doesn't exist
383386
const roomMembers = [userId, tutorId];

0 commit comments

Comments
 (0)