Update scanner (server)

This commit is contained in:
jeffvli
2022-10-29 19:12:02 -07:00
parent ff6882a6cd
commit 0200b92860
21 changed files with 777 additions and 177 deletions
+25 -15
View File
@@ -1,24 +1,34 @@
/* eslint-disable promise/catch-or-return */
import { PrismaClient } from '@prisma/client';
import bcrypt from 'bcryptjs';
import { PrismaClient, Prisma } from '@prisma/client';
import { randomString } from '../utils';
const prisma = new PrismaClient();
async function main() {
const hashedPassword = await bcrypt.hash('admin', 12);
const hashedPassword =
'$2y$12$icIH42ono1yTBypZ34V/PuDMXIbMD04GtSB6pgYpcwbjjIvujzv2y';
await prisma.user.upsert({
create: {
deviceId: `admin_${randomString(10)}`,
enabled: true,
isAdmin: true,
password: hashedPassword,
username: 'admin',
},
update: {},
where: { username: 'admin' },
});
let error;
do {
try {
await prisma.user.upsert({
create: {
deviceId: `admin_${randomString(10)}`,
enabled: true,
isAdmin: true,
password: hashedPassword,
username: 'admin',
},
update: {},
where: { username: 'admin' },
});
} catch (e) {
if (e instanceof Prisma.PrismaClientInitializationError) {
error = 'retry';
}
error = undefined;
}
} while (error === 'retry');
}
main()