-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
modif: slot_id has been added to lessons and interviews tables.
- Loading branch information
Showing
25 changed files
with
303 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ import { | |
invoices, | ||
hashPassword, | ||
topics, | ||
availabilitySlots, | ||
} from "@litespace/models"; | ||
import { IInterview, ILesson, IUser, IWithdrawMethod } from "@litespace/types"; | ||
import dayjs from "dayjs"; | ||
|
@@ -25,7 +26,7 @@ import { calculateLessonPrice } from "@litespace/sol/lesson"; | |
import { logger } from "@litespace/sol/log"; | ||
import { price } from "@litespace/sol/value"; | ||
import { IDate, IRule } from "@litespace/types"; | ||
import { first, random, range, sample } from "lodash"; | ||
import { first, range, sample } from "lodash"; | ||
import { Knex } from "knex"; | ||
import utc from "dayjs/plugin/utc"; | ||
import { faker } from "@faker-js/faker/locale/ar"; | ||
|
@@ -116,7 +117,8 @@ async function main(): Promise<void> { | |
) | ||
); | ||
|
||
const studio = await users.create({ | ||
// seeding studio user | ||
await users.create({ | ||
role: IUser.Role.Studio, | ||
email: "[email protected]", | ||
name: faker.person.fullName(), | ||
|
@@ -258,7 +260,7 @@ async function main(): Promise<void> { | |
// seeding topics data | ||
stdout.info(`Inserting at most 50 random topics in the database.`); | ||
await Promise.all( | ||
range(100).map(async (idx) => { | ||
range(100).map(async () => { | ||
try { | ||
const ar = faker.lorem.words(2); | ||
const en = fakerEn.lorem.words(2); | ||
|
@@ -285,6 +287,15 @@ async function main(): Promise<void> { | |
monthday: sample(range(1, 31)), | ||
}); | ||
|
||
// seeding slots | ||
await availabilitySlots.create(addedTutors.map(tutor => | ||
({ | ||
userId: tutor.id, | ||
start: dayjs.utc().startOf("day").toISOString(), | ||
end: dayjs.utc().startOf("day").add(30, "days").toISOString(), | ||
}) | ||
)); | ||
|
||
const times = range(0, 24).map((hour) => | ||
[hour.toString().padStart(2, "0"), "00"].join(":") | ||
); | ||
|
@@ -331,6 +342,7 @@ async function main(): Promise<void> { | |
IWithdrawMethod.Type.Instapay, | ||
]; | ||
|
||
/* Draft | ||
function randomWithdrawMethod() { | ||
const method = sample(methods)!; | ||
return { | ||
|
@@ -348,6 +360,7 @@ async function main(): Promise<void> { | |
: Math.random().toString(36).slice(2), | ||
}; | ||
} | ||
*/ | ||
|
||
async function createRandomLesson({ | ||
tutorId, | ||
|
@@ -367,6 +380,7 @@ async function main(): Promise<void> { | |
start, | ||
duration, | ||
rule: 1, | ||
slot: 1, | ||
tx, | ||
}); | ||
|
||
|
@@ -387,7 +401,7 @@ async function main(): Promise<void> { | |
await rooms.create([tutor.id, student.id]); | ||
|
||
for (const _ of range(1, 100)) { | ||
const lesson = await createRandomLesson({ | ||
await createRandomLesson({ | ||
tutorId: tutor.id, | ||
start: start.toISOString(), | ||
}); | ||
|
@@ -400,6 +414,12 @@ async function main(): Promise<void> { | |
); | ||
} | ||
|
||
const slot = (await availabilitySlots.create([{ | ||
userId: tutorManager.id, | ||
start: dayjs.utc().startOf("day").toISOString(), | ||
end: dayjs.utc().startOf("day").add(1, "days").toISOString(), | ||
}]))[0]; | ||
|
||
for (const tutor of addedTutors) { | ||
await knex.transaction(async (tx: Knex.Transaction) => { | ||
const interview = await interviews.create({ | ||
|
@@ -408,6 +428,7 @@ async function main(): Promise<void> { | |
interviewer: tutorManager.id, | ||
start: randomStart(), | ||
rule: rule.id, | ||
slot: slot.id, | ||
tx, | ||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.