Implement scoping on be (#144)
This commit is contained in:
@ -1,6 +1,11 @@
|
||||
import { INestApplication, Injectable, OnModuleInit } from '@nestjs/common';
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
|
||||
if (!global.prisma) {
|
||||
global.prisma = new PrismaClient();
|
||||
}
|
||||
export default global.prisma;
|
||||
|
||||
@Injectable()
|
||||
export class PrismaService extends PrismaClient implements OnModuleInit {
|
||||
async onModuleInit() {
|
||||
|
||||
@ -8,6 +8,11 @@ datasource db {
|
||||
url = env("SERVER_DATABASE_URL")
|
||||
}
|
||||
|
||||
generator nestgraphql {
|
||||
provider = "node node_modules/prisma-nestjs-graphql"
|
||||
output = "../../src/api/@generated"
|
||||
}
|
||||
|
||||
model User {
|
||||
id String @id
|
||||
createdAt DateTime @default(now())
|
||||
@ -69,7 +74,10 @@ model Company {
|
||||
accountOwnerId String?
|
||||
accountOwner User? @relation(fields: [accountOwnerId], references: [id])
|
||||
people Person[]
|
||||
|
||||
/// @TypeGraphQL.omit(input: true)
|
||||
workspaceId String
|
||||
/// @TypeGraphQL.omit(input: true)
|
||||
workspace Workspace @relation(fields: [workspaceId], references: [id])
|
||||
|
||||
@@map("companies")
|
||||
@ -87,7 +95,10 @@ model Person {
|
||||
city String
|
||||
companyId String?
|
||||
company Company? @relation(fields: [companyId], references: [id])
|
||||
|
||||
/// @TypeGraphQL.omit(input: true)
|
||||
workspaceId String
|
||||
/// @TypeGraphQL.omit(input: true)
|
||||
workspace Workspace @relation(fields: [workspaceId], references: [id])
|
||||
|
||||
@@map("people")
|
||||
|
||||
@ -1,15 +1,14 @@
|
||||
import { PrismaClient } from "@prisma/client";
|
||||
import { seedCompanies } from "./companies";
|
||||
import { seedWorkspaces } from "./workspaces";
|
||||
import { seedPeople } from "./people";
|
||||
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import { seedCompanies } from './companies';
|
||||
import { seedWorkspaces } from './workspaces';
|
||||
import { seedPeople } from './people';
|
||||
|
||||
const seed = async () => {
|
||||
const prisma = new PrismaClient()
|
||||
await seedWorkspaces(prisma)
|
||||
await seedCompanies(prisma)
|
||||
await seedPeople(prisma)
|
||||
await prisma.$disconnect()
|
||||
}
|
||||
|
||||
seed()
|
||||
const prisma = new PrismaClient();
|
||||
await seedWorkspaces(prisma);
|
||||
await seedCompanies(prisma);
|
||||
await seedPeople(prisma);
|
||||
await prisma.$disconnect();
|
||||
};
|
||||
|
||||
seed();
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { PrismaClient } from '@prisma/client'
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
export const seedPeople = async (prisma: PrismaClient) => {
|
||||
await prisma.person.upsert({
|
||||
where: { id: '86083141-1c0e-494c-a1b6-85b1c6fefaa5' },
|
||||
@ -11,9 +11,9 @@ export const seedPeople = async (prisma: PrismaClient) => {
|
||||
phone: '+33789012345',
|
||||
city: 'Seattle',
|
||||
companyId: 'fe256b39-3ec3-4fe3-8997-b76aa0bfa408',
|
||||
email: 'christoph.calisto@linkedin.com'
|
||||
email: 'christoph.calisto@linkedin.com',
|
||||
},
|
||||
})
|
||||
});
|
||||
|
||||
await prisma.person.upsert({
|
||||
where: { id: '0aa00beb-ac73-4797-824e-87a1f5aea9e0' },
|
||||
@ -26,9 +26,9 @@ export const seedPeople = async (prisma: PrismaClient) => {
|
||||
phone: '+33780123456',
|
||||
city: 'Los Angeles',
|
||||
companyId: 'fe256b39-3ec3-4fe3-8997-b76aa0bfa408',
|
||||
email: 'sylvie.palmer@linkedin.com'
|
||||
email: 'sylvie.palmer@linkedin.com',
|
||||
},
|
||||
})
|
||||
});
|
||||
|
||||
await prisma.person.upsert({
|
||||
where: { id: '93c72d2e-f517-42fd-80ae-14173b3b70ae' },
|
||||
@ -41,10 +41,10 @@ export const seedPeople = async (prisma: PrismaClient) => {
|
||||
phone: '+33789012345',
|
||||
city: 'Seattle',
|
||||
companyId: '04b2e9f5-0713-40a5-8216-82802401d33e',
|
||||
email: 'christopher.gonzalez@qonto.com'
|
||||
email: 'christopher.gonzalez@qonto.com',
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
await prisma.person.upsert({
|
||||
where: { id: 'eeeacacf-eee1-4690-ad2c-8619e5b56a2e' },
|
||||
update: {},
|
||||
@ -56,10 +56,10 @@ export const seedPeople = async (prisma: PrismaClient) => {
|
||||
phone: '+33780123456',
|
||||
city: 'Los Angeles',
|
||||
companyId: '04b2e9f5-0713-40a5-8216-82802401d33e',
|
||||
email: 'ashley.parker@qonto.com'
|
||||
email: 'ashley.parker@qonto.com',
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
await prisma.person.upsert({
|
||||
where: { id: '9b324a88-6784-4449-afdf-dc62cb8702f2' },
|
||||
update: {},
|
||||
@ -71,10 +71,10 @@ export const seedPeople = async (prisma: PrismaClient) => {
|
||||
phone: '+33781234567',
|
||||
city: 'Seattle',
|
||||
companyId: '460b6fb1-ed89-413a-b31a-962986e67bb4',
|
||||
email: 'nicholas.wright@microsoft.com'
|
||||
email: 'nicholas.wright@microsoft.com',
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
await prisma.person.upsert({
|
||||
where: { id: '1d151852-490f-4466-8391-733cfd66a0c8' },
|
||||
update: {},
|
||||
@ -86,10 +86,10 @@ export const seedPeople = async (prisma: PrismaClient) => {
|
||||
phone: '+33782345678',
|
||||
city: 'New York',
|
||||
companyId: '460b6fb1-ed89-413a-b31a-962986e67bb4',
|
||||
email: 'isabella.scott@microsoft.com'
|
||||
email: 'isabella.scott@microsoft.com',
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
await prisma.person.upsert({
|
||||
where: { id: '98406e26-80f1-4dff-b570-a74942528de3' },
|
||||
update: {},
|
||||
@ -101,7 +101,7 @@ export const seedPeople = async (prisma: PrismaClient) => {
|
||||
phone: '+33783456789',
|
||||
city: 'Seattle',
|
||||
companyId: '460b6fb1-ed89-413a-b31a-962986e67bb4',
|
||||
email: 'matthew.green@microsoft.com'
|
||||
email: 'matthew.green@microsoft.com',
|
||||
},
|
||||
});
|
||||
|
||||
@ -116,10 +116,10 @@ export const seedPeople = async (prisma: PrismaClient) => {
|
||||
phone: '+33784567890',
|
||||
city: 'New York',
|
||||
companyId: '89bb825c-171e-4bcc-9cf7-43448d6fb278',
|
||||
email: 'elizabeth.baker@airbnb.com'
|
||||
email: 'elizabeth.baker@airbnb.com',
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
await prisma.person.upsert({
|
||||
where: { id: 'ca1f5bf3-64ad-4b0e-bbfd-e9fd795b7016' },
|
||||
update: {},
|
||||
@ -131,10 +131,10 @@ export const seedPeople = async (prisma: PrismaClient) => {
|
||||
phone: '+33785678901',
|
||||
city: 'San Francisco',
|
||||
companyId: '89bb825c-171e-4bcc-9cf7-43448d6fb278',
|
||||
email: 'christopher.nelson@airbnb.com'
|
||||
email: 'christopher.nelson@airbnb.com',
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
await prisma.person.upsert({
|
||||
where: { id: '56955422-5d54-41b7-ba36-f0d20e1417ae' },
|
||||
update: {},
|
||||
@ -146,10 +146,10 @@ export const seedPeople = async (prisma: PrismaClient) => {
|
||||
phone: '+33786789012',
|
||||
city: 'New York',
|
||||
companyId: '89bb825c-171e-4bcc-9cf7-43448d6fb278',
|
||||
email: 'avery.carter@airbnb.com'
|
||||
email: 'avery.carter@airbnb.com',
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
await prisma.person.upsert({
|
||||
where: { id: '755035db-623d-41fe-92e7-dd45b7c568e1' },
|
||||
update: {},
|
||||
@ -161,22 +161,52 @@ export const seedPeople = async (prisma: PrismaClient) => {
|
||||
phone: '+33787890123',
|
||||
city: 'Los Angeles',
|
||||
companyId: '0d940997-c21e-4ec2-873b-de4264d89025',
|
||||
email: 'ethan.mitchell@google.com'
|
||||
email: 'ethan.mitchell@google.com',
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
await prisma.person.upsert({
|
||||
where: { id: '240da2ec-2d40-4e49-8df4-9c6a049190df' },
|
||||
where: { id: '240da2ec-2d40-4e49-8df4-9c6a049190ef' },
|
||||
update: {},
|
||||
create: {
|
||||
id: '240da2ec-2d40-4e49-8df4-9c6a049190df',
|
||||
id: '240da2ec-2d40-4e49-8df4-9c6a049190ef',
|
||||
firstname: 'Madison',
|
||||
lastname: 'Perez',
|
||||
workspaceId: '7ed9d212-1c25-4d02-bf25-6aeccf7ea419',
|
||||
phone: '+33788901234',
|
||||
city: 'Seattle',
|
||||
companyId: '0d940997-c21e-4ec2-873b-de4264d89025',
|
||||
email: 'madison.perez@google.com'
|
||||
email: 'madison.perez@google.com',
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
await prisma.person.upsert({
|
||||
where: { id: '240da2ec-2d40-4e49-8df4-9c6a049190df' },
|
||||
update: {},
|
||||
create: {
|
||||
id: '240da2ec-2d40-4e49-8df4-9c6a049190df',
|
||||
firstname: 'Bertrand',
|
||||
lastname: 'Voulzy',
|
||||
workspaceId: '7ed9d212-1c25-4d02-bf25-6aeccf7ea419',
|
||||
phone: '+33788901234',
|
||||
city: 'Seattle',
|
||||
companyId: '0d940997-c21e-4ec2-873b-de4264d89025',
|
||||
email: 'bertrand.voulzy@google.com',
|
||||
},
|
||||
});
|
||||
|
||||
await prisma.person.upsert({
|
||||
where: { id: '240da2ec-2d40-4e49-8df4-9c6a049190dg' },
|
||||
update: {},
|
||||
create: {
|
||||
id: '240da2ec-2d40-4e49-8df4-9c6a049190dg',
|
||||
firstname: 'Louis',
|
||||
lastname: 'Duss',
|
||||
workspaceId: '7ed9d212-1c25-4d02-bf25-6aeccf7ea419',
|
||||
phone: '+33788901234',
|
||||
city: 'Seattle',
|
||||
companyId: '0d940997-c21e-4ec2-873b-de4264d89025',
|
||||
email: 'louis.duss@google.com',
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user