added tons of features
This commit is contained in:
28
lib/db/prisma/seed/main.ts
Normal file
28
lib/db/prisma/seed/main.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import {Prisma, PrismaClient, Store} from '@prisma/client'
|
||||
import {DefaultArgs} from '@prisma/client/runtime/library'
|
||||
|
||||
import {storeSeed} from '@/lib/db/prisma/seed/store'
|
||||
|
||||
export type prismaClientType = PrismaClient<
|
||||
Prisma.PrismaClientOptions,
|
||||
never,
|
||||
DefaultArgs
|
||||
>
|
||||
|
||||
const prisma = new PrismaClient()
|
||||
|
||||
async function main() {
|
||||
console.log('!!!!')
|
||||
|
||||
console.log(await storeSeed(prisma))
|
||||
}
|
||||
|
||||
main()
|
||||
.then(async () => {
|
||||
await prisma.$disconnect()
|
||||
})
|
||||
.catch(async e => {
|
||||
console.error(e)
|
||||
await prisma.$disconnect()
|
||||
process.exit(1)
|
||||
})
|
||||
55
lib/db/prisma/seed/store.ts
Normal file
55
lib/db/prisma/seed/store.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import {Store} from '@prisma/client'
|
||||
|
||||
import {type prismaClientType} from '@/lib/db/prisma/seed/main'
|
||||
import {slug} from '@/lib/utils'
|
||||
|
||||
const STORE_TITLE = 'Be Well'
|
||||
const STORE_TITLE_RU = STORE_TITLE
|
||||
|
||||
export const storeSeed = async function (prisma: prismaClientType) {
|
||||
const store: Store = await prisma.store.create({
|
||||
data: {
|
||||
slug: slug(STORE_TITLE),
|
||||
active: true,
|
||||
image: '/images/logo.svg',
|
||||
storeLocale: {
|
||||
create: [
|
||||
{
|
||||
title: STORE_TITLE,
|
||||
lang: 'uk',
|
||||
motto: 'подбай про себе',
|
||||
slug: slug(STORE_TITLE, 'uk')
|
||||
// meta: {
|
||||
// create: {
|
||||
// keywords: ['харчові добавки', 'вітаміни'],
|
||||
// openGraph: {
|
||||
// create: {
|
||||
// locale: 'uk_UA'
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
},
|
||||
{
|
||||
title: STORE_TITLE_RU,
|
||||
lang: 'ru',
|
||||
motto: 'позаботься о себе',
|
||||
slug: slug(STORE_TITLE_RU, 'ru')
|
||||
// meta: {
|
||||
// create: {
|
||||
// keywords: ['пищевые добавки', 'витамины'],
|
||||
// openGraph: {
|
||||
// create: {
|
||||
// locale: 'ru_UA'
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
return store
|
||||
}
|
||||
24
lib/db/prisma/seed/user.ts
Normal file
24
lib/db/prisma/seed/user.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import {User} from '@prisma/client'
|
||||
import * as argon2 from 'argon2'
|
||||
|
||||
import type {prismaClientType} from '@/lib/db/prisma/seed/main'
|
||||
import {hashPassword} from '@/lib/utils'
|
||||
|
||||
export const superUserSeed = async function (prisma: prismaClientType) {
|
||||
// const hashedPassword = await hashPassword('b00st!667')
|
||||
//
|
||||
// console.log(hashedPassword, await argon2.verify(hashedPassword, 'b00st!667'))
|
||||
|
||||
const user: User = await prisma.user.create({
|
||||
data: {
|
||||
locale: 'uk',
|
||||
active: true,
|
||||
name: 'Yevhen Odynets',
|
||||
username: 'sv-yeod',
|
||||
email: 'yevhen.odynets@ugmail.org',
|
||||
password: 'hashedPassword'
|
||||
}
|
||||
})
|
||||
|
||||
return user
|
||||
}
|
||||
Reference in New Issue
Block a user