Skip to content

Commit

Permalink
added: seeding data for topics table
Browse files Browse the repository at this point in the history
  • Loading branch information
mmoehabb committed Dec 23, 2024
1 parent 8e42d4f commit b8fcb9b
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion packages/models/scripts/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ import {
withdrawMethods,
invoices,
hashPassword,
topics,
} from "@litespace/models";
import {
ICall,
IInterview,
ILesson,
IRating,
IUser,
IWithdrawMethod,
} from "@litespace/types";
Expand Down Expand Up @@ -256,6 +256,29 @@ async function main(): Promise<void> {
);
});

// seeding topics data
await knex.transaction(async (tx) => {
stdout.info(`Inserting 50 random topics in the database.`);

const mockTopics = faker.lorem.words(50).split(" ");
for (let i = 0; i < mockTopics.length; i++) {
if (mockTopics.slice(i+1, mockTopics.length).includes(mockTopics[i])) {
mockTopics[i] = "_" + mockTopics[i] + "_";
}
}

return await Promise.all(
mockTopics.map(async (topic: string) => {
await topics.create({
name: {
ar: topic,
en: topic,
}
}, tx);
})
);
});

const rule = await rules.create({
userId: tutorManager.id,
frequency: IRule.Frequency.Daily,
Expand Down

0 comments on commit b8fcb9b

Please sign in to comment.