feat: default pipeline provisioning at workspace creation (#728)

* feat: default pipeline and pipeline stage on workspace creation

* Create seed data files, typo

* Naming

---------

Co-authored-by: Emilien <emilien.chauvet.enpc@gmail.com>
This commit is contained in:
Jérémy M
2023-07-18 19:30:59 +02:00
committed by GitHub
parent f65d2f418e
commit 4ec93d4b6a
10 changed files with 141 additions and 18 deletions

View File

@ -1,5 +1,6 @@
import { Injectable } from '@nestjs/common';
import { PrismaService } from 'src/database/prisma.service';
import seedPipelineStages from '../seed-data/pipeline-stages.json';
@Injectable()
export class PipelineStageService {
@ -35,4 +36,22 @@ export class PipelineStageService {
// GroupBy
groupBy = this.prismaService.pipelineStage.groupBy;
// Customs
async createDefaultPipelineStages({
workspaceId,
pipelineId,
}: {
workspaceId: string;
pipelineId: string;
}) {
const pipelineStages = seedPipelineStages.map((pipelineStage) => ({
...pipelineStage,
workspaceId,
pipelineId,
}));
return this.createMany({
data: pipelineStages,
});
}
}

View File

@ -1,5 +1,7 @@
import { Injectable } from '@nestjs/common';
import { PrismaService } from 'src/database/prisma.service';
import seedSalesPipeline from '../seed-data/sales-pipeline.json';
import { PipelineProgressableType } from '@prisma/client';
@Injectable()
export class PipelineService {
@ -35,4 +37,18 @@ export class PipelineService {
// GroupBy
groupBy = this.prismaService.pipeline.groupBy;
// Customs
async createDefaultPipeline({ workspaceId }: { workspaceId: string }) {
const pipeline = {
...seedSalesPipeline,
pipelineProgressableType:
seedSalesPipeline.pipelineProgressableType as PipelineProgressableType,
workspaceId,
};
return this.create({
data: pipeline,
});
}
}