feat: create default opportunities view on workspace creation + add seed data (#1461)

Closes #1314
This commit is contained in:
Thaïs
2023-09-06 12:05:33 +02:00
committed by GitHub
parent 08b56ec7e2
commit 5c7660f588
8 changed files with 106 additions and 30 deletions

View File

@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "viewFields" ALTER COLUMN "size" DROP NOT NULL;

View File

@ -662,7 +662,7 @@ model ViewField {
key String
name String
objectId String
size Int
size Int?
view View @relation(fields: [viewId], references: [id], onDelete: Cascade)
viewId String

View File

@ -4,6 +4,7 @@ export const seedViews = async (prisma: PrismaClient) => {
const workspaceId = 'twenty-7ed9d212-1c25-4d02-bf25-6aeccf7ea419';
const companyViewId = 'twenty-5e924b69-a619-41bf-bd31-a9e8551fc9d1';
const personViewId = 'twenty-db9e6c85-c091-4fd6-88b1-c1830f5e90d1';
const opportunitiesViewId = 'twenty-6abb47a2-7a91-4679-a538-59946f0c06a9';
await prisma.view.upsert({
where: { id: companyViewId },
@ -149,4 +150,52 @@ export const seedViews = async (prisma: PrismaClient) => {
}),
),
);
await prisma.view.upsert({
where: { id: opportunitiesViewId },
update: {},
create: {
id: opportunitiesViewId,
name: 'All Opportunities',
objectId: 'company',
type: 'Pipeline',
workspaceId,
},
});
await Promise.all(
[
{
key: 'closeDate',
name: 'Close Date',
},
{
key: 'amount',
name: 'Amount',
},
{
key: 'probability',
name: 'Probability',
},
{
key: 'pointOfContact',
name: 'Point of Contact',
},
].map((viewField, index) =>
prisma.viewField.upsert({
where: {
viewId_key: { key: viewField.key, viewId: opportunitiesViewId },
},
update: {},
create: {
...viewField,
index,
isVisible: true,
objectId: 'company',
viewId: opportunitiesViewId,
workspaceId,
},
}),
),
);
};