diff --git a/apps/api/project.json b/apps/api/project.json index 54933d1..0d50e5b 100644 --- a/apps/api/project.json +++ b/apps/api/project.json @@ -103,7 +103,7 @@ "executor": "@nx-tools/nx-prisma:seed", "options": { "schema": "apps/api/prisma/schema.prisma", - "script": "apps/api/prisma/seed.ts" + "script": "apps/api/src/seed.ts" } }, "prisma-validate": { diff --git a/apps/api/src/seed.ts b/apps/api/src/seed.ts new file mode 100644 index 0000000..ff8a7f9 --- /dev/null +++ b/apps/api/src/seed.ts @@ -0,0 +1,46 @@ +import { $Enums, PrismaClient } from "@prisma/client"; +//eslint-disable-next-line @nx/enforce-module-boundaries +import * as utils from "./util/encryption"; + +const prisma = new PrismaClient(); +async function main() { + const operators = [1, 2, 3, 4, 5].map(async (number: number) => { + return await prisma.user.create({ + data: { + name: `Operator ${number}`, + username: `operator${number}`, + password: await utils.hash(`operator${number}`), + phoneNumber: `+6281234567891${number}`, + role: $Enums.Role.operator, + active: true, + description: null, + }, + }); + }); + + const admin = [1, 2, 3, 4, 5].map(async (number: number) => { + return await prisma.user.create({ + data: { + name: `Admin ${number}`, + username: `admin${number}`, + password: await utils.hash(`admin${number}`), + phoneNumber: `+6281234567892${number}`, + role: $Enums.Role.admin, + active: true, + description: null, + }, + }); + }); + + console.log({ operators, admin }); +} + +main() + .then(async () => { + await prisma.$disconnect(); + }) + .catch(async (e) => { + console.error(e); + await prisma.$disconnect(); + process.exit(1); + });