This repository has been archived by the owner on Oct 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
54 additions
and
58 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,49 @@ | ||
import prisma from "@/config/database"; | ||
import { faker } from "@faker-js/faker"; | ||
import { Prisma, PrismaClient } from "@prisma/client"; | ||
import { Prisma } from "@prisma/client"; | ||
import * as Factory from "factory.ts"; | ||
|
||
const { commerce, internet, person } = faker; | ||
const prisma = new PrismaClient(); | ||
|
||
export interface TableList { | ||
TABLE_NAME: string; | ||
TABLE_NAME: string; | ||
} | ||
|
||
export const userFactory = | ||
Factory.Sync.makeFactory<Prisma.UserUncheckedCreateInput>({ | ||
name: Factory.Sync.each(() => { | ||
return person.firstName(); | ||
}), | ||
surname: Factory.Sync.each(() => { | ||
return person.lastName(); | ||
}), | ||
email: Factory.Sync.each((seq) => { | ||
return `seq_${seq}_${internet.email()}`; | ||
}), | ||
password: Factory.Sync.each(() => { | ||
return internet.password(); | ||
}), | ||
}); | ||
Factory.Sync.makeFactory<Prisma.UserUncheckedCreateInput>({ | ||
name: Factory.Sync.each(() => { | ||
return person.firstName(); | ||
}), | ||
surname: Factory.Sync.each(() => { | ||
return person.lastName(); | ||
}), | ||
email: Factory.Sync.each((seq) => { | ||
return `seq_${seq}_${internet.email()}`; | ||
}), | ||
password: Factory.Sync.each(() => { | ||
return internet.password(); | ||
}), | ||
}); | ||
|
||
export const postFactory = | ||
Factory.Sync.makeFactory<Prisma.PostUncheckedCreateInput>({ | ||
title: Factory.Sync.each(() => { | ||
return commerce.productName(); | ||
}), | ||
content: Factory.Sync.each(() => { | ||
return commerce.productDescription(); | ||
}), | ||
published: true, | ||
}); | ||
Factory.Sync.makeFactory<Prisma.PostUncheckedCreateInput>({ | ||
title: Factory.Sync.each(() => { | ||
return commerce.productName(); | ||
}), | ||
content: Factory.Sync.each(() => { | ||
return commerce.productDescription(); | ||
}), | ||
published: true, | ||
}); | ||
|
||
export const clearData = async () => { | ||
try { | ||
const posts = await prisma.post.deleteMany(); | ||
const users = await prisma.user.deleteMany(); | ||
try { | ||
const posts = await prisma.post.deleteMany(); | ||
const users = await prisma.user.deleteMany(); | ||
|
||
console.log({ posts, users }); | ||
} catch (error) { | ||
console.error(error); | ||
return error; | ||
} | ||
console.log({ posts, users }); | ||
} catch (error) { | ||
console.error(error); | ||
return error; | ||
} | ||
}; |
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