feat: create default views on workspace creation + add views seed (#1313)

Closes #1311
This commit is contained in:
Thaïs
2023-08-25 21:17:28 +02:00
committed by GitHub
parent 8a3a176571
commit 209e8b64d9
11 changed files with 356 additions and 16 deletions

View File

@ -0,0 +1,111 @@
[
{
"name": "All Companies",
"objectId": "company",
"type": "Table",
"fields": [
{
"fieldName": "Name",
"sizeInPx": 180,
"isVisible": true
},
{
"fieldName": "URL",
"sizeInPx": 100,
"isVisible": true
},
{
"fieldName": "Account Owner",
"sizeInPx": 150,
"isVisible": true
},
{
"fieldName": "Creation",
"sizeInPx": 150,
"isVisible": true
},
{
"fieldName": "Employees",
"sizeInPx": 150,
"isVisible": true
},
{
"fieldName": "LinkedIn",
"sizeInPx": 170,
"isVisible": true
},
{
"fieldName": "Address",
"sizeInPx": 170,
"isVisible": true
},
{
"fieldName": "ICP",
"sizeInPx": 150,
"isVisible": false
},
{
"fieldName": "ARR",
"sizeInPx": 150,
"isVisible": true
},
{
"fieldName": "Twitter",
"sizeInPx": 150,
"isVisible": false
}
]
},
{
"name": "All People",
"objectId": "person",
"type": "Table",
"fields": [
{
"fieldName": "People",
"sizeInPx": 210,
"isVisible": true
},
{
"fieldName": "Email",
"sizeInPx": 150,
"isVisible": true
},
{
"fieldName": "Company",
"sizeInPx": 150,
"isVisible": true
},
{
"fieldName": "Phone",
"sizeInPx": 150,
"isVisible": true
},
{
"fieldName": "Creation",
"sizeInPx": 150,
"isVisible": true
},
{
"fieldName": "City",
"sizeInPx": 150,
"isVisible": true
},
{
"fieldName": "Job title",
"sizeInPx": 150,
"isVisible": true
},
{
"fieldName": "LinkedIn",
"sizeInPx": 150,
"isVisible": true
},
{
"fieldName": "Twitter",
"sizeInPx": 150,
"isVisible": true
}
]
}
]

View File

@ -1,6 +1,9 @@
import { Injectable } from '@nestjs/common';
import type { ViewType } from '@prisma/client';
import { PrismaService } from 'src/database/prisma.service';
import seedViews from 'src/core/view/seed-data/views.json';
@Injectable()
export class ViewService {
@ -36,4 +39,29 @@ export class ViewService {
// GroupBy
groupBy = this.prismaService.client.view.groupBy;
// Custom
createDefaultViews({ workspaceId }: { workspaceId: string }) {
return Promise.all(
seedViews.map(async ({ fields, ...viewInput }) => {
const view = await this.create({
data: {
...viewInput,
type: viewInput.type as ViewType,
workspace: { connect: { id: workspaceId } },
},
});
await this.prismaService.client.viewField.createMany({
data: fields.map((viewField, index) => ({
...viewField,
objectName: view.objectId,
index: index + 1,
viewId: view.id,
workspaceId,
})),
});
}),
);
}
}

View File

@ -20,5 +20,6 @@ import { ViewFilterResolver } from './resolvers/view-filter.resolver';
ViewFilterResolver,
ViewSortResolver,
],
exports: [ViewService],
})
export class ViewModule {}