Skip to content

Commit 66d7248

Browse files
authored
Merge pull request #83 from ES2-UFPI/developer
Developer
2 parents 26e5952 + 4a847d5 commit 66d7248

File tree

393 files changed

+17554
-2814
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

393 files changed

+17554
-2814
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
-- CreateTable
2+
CREATE TABLE "fields" (
3+
"id" TEXT NOT NULL,
4+
"name" TEXT NOT NULL,
5+
"value" TEXT,
6+
"parentId" TEXT,
7+
"ready" BOOLEAN DEFAULT false,
8+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
9+
"updatedAt" TIMESTAMP(3),
10+
"documentId" TEXT NOT NULL,
11+
12+
CONSTRAINT "fields_pkey" PRIMARY KEY ("id")
13+
);
14+
15+
-- CreateTable
16+
CREATE TABLE "documents" (
17+
"id" TEXT NOT NULL,
18+
"name" TEXT NOT NULL,
19+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
20+
"updatedAt" TIMESTAMP(3),
21+
"opportunityId" TEXT,
22+
"projectTypeId" TEXT,
23+
24+
CONSTRAINT "documents_pkey" PRIMARY KEY ("id")
25+
);
26+
27+
-- CreateTable
28+
CREATE TABLE "project_types" (
29+
"id" TEXT NOT NULL,
30+
"name" TEXT NOT NULL,
31+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
32+
"updatedAt" TIMESTAMP(3),
33+
34+
CONSTRAINT "project_types_pkey" PRIMARY KEY ("id")
35+
);
36+
37+
-- CreateIndex
38+
CREATE UNIQUE INDEX "project_types_name_key" ON "project_types"("name");
39+
40+
-- AddForeignKey
41+
ALTER TABLE "fields" ADD CONSTRAINT "fields_parentId_fkey" FOREIGN KEY ("parentId") REFERENCES "fields"("id") ON DELETE CASCADE ON UPDATE CASCADE;
42+
43+
-- AddForeignKey
44+
ALTER TABLE "fields" ADD CONSTRAINT "fields_documentId_fkey" FOREIGN KEY ("documentId") REFERENCES "documents"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
45+
46+
-- AddForeignKey
47+
ALTER TABLE "documents" ADD CONSTRAINT "documents_opportunityId_fkey" FOREIGN KEY ("opportunityId") REFERENCES "opportunities"("id") ON DELETE SET NULL ON UPDATE CASCADE;
48+
49+
-- AddForeignKey
50+
ALTER TABLE "documents" ADD CONSTRAINT "documents_projectTypeId_fkey" FOREIGN KEY ("projectTypeId") REFERENCES "project_types"("id") ON DELETE SET NULL ON UPDATE CASCADE;
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
-- CreateTable
2+
CREATE TABLE "requested_itens" (
3+
"id" TEXT NOT NULL,
4+
"quantity" DECIMAL(65,30) NOT NULL,
5+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
6+
"updatedAt" TIMESTAMP(3),
7+
"baseProductId" TEXT NOT NULL,
8+
"allocationDepartmentId" TEXT,
9+
"maintenanceContractId" TEXT,
10+
"projectId" TEXT NOT NULL,
11+
12+
CONSTRAINT "requested_itens_pkey" PRIMARY KEY ("id")
13+
);
14+
15+
-- CreateTable
16+
CREATE TABLE "projects" (
17+
"id" TEXT NOT NULL,
18+
"title" TEXT NOT NULL,
19+
"responsibleCpf" TEXT,
20+
"responsibleName" TEXT,
21+
"responsibleEmail" TEXT,
22+
"responsiblePhone" TEXT,
23+
"counterpartCapitalItem" TEXT,
24+
"counterpartCapitalValue" DECIMAL(65,30),
25+
"counterpartOperatingCostCode" TEXT,
26+
"counterpartOperatingCostValue" DECIMAL(65,30),
27+
"totalValue" DECIMAL(65,30),
28+
"requestedValue" DECIMAL(65,30),
29+
"baseValue" DECIMAL(65,30),
30+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
31+
"updatedAt" TIMESTAMP(3),
32+
"projectTypeId" TEXT NOT NULL,
33+
"opportunityId" TEXT NOT NULL,
34+
"municipalityId" TEXT NOT NULL,
35+
36+
CONSTRAINT "projects_pkey" PRIMARY KEY ("id")
37+
);
38+
39+
-- CreateTable
40+
CREATE TABLE "_DocumentToProject" (
41+
"A" TEXT NOT NULL,
42+
"B" TEXT NOT NULL,
43+
44+
CONSTRAINT "_DocumentToProject_AB_pkey" PRIMARY KEY ("A","B")
45+
);
46+
47+
-- CreateIndex
48+
CREATE INDEX "_DocumentToProject_B_index" ON "_DocumentToProject"("B");
49+
50+
-- AddForeignKey
51+
ALTER TABLE "requested_itens" ADD CONSTRAINT "requested_itens_baseProductId_fkey" FOREIGN KEY ("baseProductId") REFERENCES "base_products"("id") ON DELETE CASCADE ON UPDATE CASCADE;
52+
53+
-- AddForeignKey
54+
ALTER TABLE "requested_itens" ADD CONSTRAINT "requested_itens_allocationDepartmentId_fkey" FOREIGN KEY ("allocationDepartmentId") REFERENCES "allocation_departments"("id") ON DELETE CASCADE ON UPDATE CASCADE;
55+
56+
-- AddForeignKey
57+
ALTER TABLE "requested_itens" ADD CONSTRAINT "requested_itens_maintenanceContractId_fkey" FOREIGN KEY ("maintenanceContractId") REFERENCES "maintenance_contracts"("id") ON DELETE CASCADE ON UPDATE CASCADE;
58+
59+
-- AddForeignKey
60+
ALTER TABLE "requested_itens" ADD CONSTRAINT "requested_itens_projectId_fkey" FOREIGN KEY ("projectId") REFERENCES "projects"("id") ON DELETE CASCADE ON UPDATE CASCADE;
61+
62+
-- AddForeignKey
63+
ALTER TABLE "projects" ADD CONSTRAINT "projects_projectTypeId_fkey" FOREIGN KEY ("projectTypeId") REFERENCES "project_types"("id") ON DELETE CASCADE ON UPDATE CASCADE;
64+
65+
-- AddForeignKey
66+
ALTER TABLE "projects" ADD CONSTRAINT "projects_opportunityId_fkey" FOREIGN KEY ("opportunityId") REFERENCES "opportunities"("id") ON DELETE CASCADE ON UPDATE CASCADE;
67+
68+
-- AddForeignKey
69+
ALTER TABLE "projects" ADD CONSTRAINT "projects_municipalityId_fkey" FOREIGN KEY ("municipalityId") REFERENCES "municipalities"("id") ON DELETE CASCADE ON UPDATE CASCADE;
70+
71+
-- AddForeignKey
72+
ALTER TABLE "_DocumentToProject" ADD CONSTRAINT "_DocumentToProject_A_fkey" FOREIGN KEY ("A") REFERENCES "documents"("id") ON DELETE CASCADE ON UPDATE CASCADE;
73+
74+
-- AddForeignKey
75+
ALTER TABLE "_DocumentToProject" ADD CONSTRAINT "_DocumentToProject_B_fkey" FOREIGN KEY ("B") REFERENCES "projects"("id") ON DELETE CASCADE ON UPDATE CASCADE;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- DropForeignKey
2+
ALTER TABLE "requested_itens" DROP CONSTRAINT "requested_itens_projectId_fkey";
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
-- CreateTable
2+
CREATE TABLE "opportunity_project_types" (
3+
"id" TEXT NOT NULL,
4+
"opportunityId" TEXT NOT NULL,
5+
"projectTypeId" TEXT NOT NULL,
6+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
7+
"updatedAt" TIMESTAMP(3),
8+
9+
CONSTRAINT "opportunity_project_types_pkey" PRIMARY KEY ("id")
10+
);
11+
12+
-- CreateIndex
13+
CREATE UNIQUE INDEX "opportunity_project_types_opportunityId_projectTypeId_key" ON "opportunity_project_types"("opportunityId", "projectTypeId");
14+
15+
-- AddForeignKey
16+
ALTER TABLE "opportunity_project_types" ADD CONSTRAINT "opportunity_project_types_opportunityId_fkey" FOREIGN KEY ("opportunityId") REFERENCES "opportunities"("id") ON DELETE CASCADE ON UPDATE CASCADE;
17+
18+
-- AddForeignKey
19+
ALTER TABLE "opportunity_project_types" ADD CONSTRAINT "opportunity_project_types_projectTypeId_fkey" FOREIGN KEY ("projectTypeId") REFERENCES "project_types"("id") ON DELETE CASCADE ON UPDATE CASCADE;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- AddForeignKey
2+
ALTER TABLE "requested_itens" ADD CONSTRAINT "requested_itens_projectId_fkey" FOREIGN KEY ("projectId") REFERENCES "projects"("id") ON DELETE CASCADE ON UPDATE CASCADE;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- AlterEnum
2+
ALTER TYPE "Role" ADD VALUE 'COMPANY';

api/prisma/schema.prisma

Lines changed: 104 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ enum Role {
2222
ADMIN
2323
MUNICIPALITY
2424
ADMIN_MASTER
25+
COMPANY
2526
}
2627

2728
enum TypeGroup {
@@ -86,6 +87,7 @@ model Municipality {
8687
8788
createdAt DateTime @default(now())
8889
updatedAt DateTime? @updatedAt
90+
Project Project[]
8991
9092
@@map("municipalities")
9193
}
@@ -98,8 +100,9 @@ model AllocationDepartment {
98100
municipalityId String
99101
municipality Municipality @relation(fields: [municipalityId], references: [id], onDelete: Cascade)
100102
101-
createdAt DateTime @default(now())
102-
updatedAt DateTime? @updatedAt
103+
createdAt DateTime @default(now())
104+
updatedAt DateTime? @updatedAt
105+
RequestedItem RequestedItem[]
103106
104107
@@map("allocation_departments")
105108
}
@@ -112,8 +115,9 @@ model MaintenanceContract {
112115
municipalityId String
113116
municipality Municipality @relation(fields: [municipalityId], references: [id], onDelete: Cascade)
114117
115-
createdAt DateTime @default(now())
116-
updatedAt DateTime? @updatedAt
118+
createdAt DateTime @default(now())
119+
updatedAt DateTime? @updatedAt
120+
RequestedItem RequestedItem[]
117121
118122
@@map("maintenance_contracts")
119123
}
@@ -219,15 +223,53 @@ model Opportunity {
219223
createdAt DateTime @default(now())
220224
updatedAt DateTime? @updatedAt
221225
222-
Type Type @relation(fields: [typeId], references: [id], onDelete: Cascade)
226+
type Type @relation(fields: [typeId], references: [id], onDelete: Cascade)
223227
typeId String
224228
225-
requiredDocuments RequiredDocument[]
226-
documents Document[]
229+
requiredDocuments RequiredDocument[]
230+
projects Project[]
231+
documents Document[]
232+
OpportunityProjectType OpportunityProjectType[]
227233
228234
@@map("opportunities")
229235
}
230236

237+
model OpportunityProjectType {
238+
id String @id @default(uuid())
239+
opportunity Opportunity @relation(fields: [opportunityId], references: [id], onDelete: Cascade)
240+
opportunityId String
241+
projectType ProjectType @relation(fields: [projectTypeId], references: [id], onDelete: Cascade)
242+
projectTypeId String
243+
244+
createdAt DateTime @default(now())
245+
updatedAt DateTime? @updatedAt
246+
247+
@@unique([opportunityId, projectTypeId])
248+
@@map("opportunity_project_types")
249+
}
250+
251+
model RequestedItem {
252+
id String @id @default(uuid())
253+
quantity Decimal
254+
255+
createdAt DateTime @default(now())
256+
updatedAt DateTime? @updatedAt
257+
258+
baseProduct BaseProduct @relation(fields: [baseProductId], references: [id], onDelete: Cascade)
259+
baseProductId String
260+
261+
allocationDepartment AllocationDepartment? @relation(fields: [allocationDepartmentId], references: [id], onDelete: Cascade)
262+
allocationDepartmentId String?
263+
264+
maintenanceContract MaintenanceContract? @relation(fields: [maintenanceContractId], references: [id], onDelete: Cascade)
265+
maintenanceContractId String?
266+
267+
project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
268+
projectId String
269+
270+
@@map("requested_itens")
271+
}
272+
231273
model BaseProduct {
232274
id String @id @default(uuid())
233275
code String @unique
@@ -246,8 +288,9 @@ model BaseProduct {
246288
247289
SpecificProduct SpecificProduct[]
248290
249-
createdAt DateTime @default(now())
250-
updatedAt DateTime? @updatedAt
291+
createdAt DateTime @default(now())
292+
updatedAt DateTime? @updatedAt
293+
RequestedItem RequestedItem[]
251294
252295
@@map("base_products")
253296
}
@@ -300,7 +343,58 @@ model Document {
300343
opportunity Opportunity? @relation(fields: [opportunityId], references: [id])
301344
opportunityId String?
302345
303-
fields Field[]
346+
projectType ProjectType? @relation(fields: [projectTypeId], references: [id])
347+
projectTypeId String?
348+
349+
fields Field[]
350+
Project Project[]
304351
305352
@@map("documents")
306353
}
354+
355+
model ProjectType {
356+
id String @id @default(uuid())
357+
name String @unique
358+
359+
createdAt DateTime @default(now())
360+
updatedAt DateTime? @updatedAt
361+
362+
documents Document[]
363+
Project Project[]
364+
OpportunityProjectType OpportunityProjectType[]
365+
366+
@@map("project_types")
367+
}
368+
369+
model Project {
370+
id String @id @default(uuid())
371+
title String
372+
responsibleCpf String?
373+
responsibleName String?
374+
responsibleEmail String?
375+
responsiblePhone String?
376+
counterpartCapitalItem String?
377+
counterpartCapitalValue Decimal?
378+
counterpartOperatingCostCode String?
379+
counterpartOperatingCostValue Decimal?
380+
totalValue Decimal?
381+
requestedValue Decimal?
382+
baseValue Decimal?
383+
384+
createdAt DateTime @default(now())
385+
updatedAt DateTime? @updatedAt
386+
387+
projectType ProjectType @relation(fields: [projectTypeId], references: [id], onDelete: Cascade)
388+
projectTypeId String
389+
390+
opportunity Opportunity @relation(fields: [opportunityId], references: [id], onDelete: Cascade)
391+
opportunityId String
392+
393+
municipality Municipality @relation(fields: [municipalityId], references: [id], onDelete: Cascade)
394+
municipalityId String
395+
396+
documents Document[]
397+
requestedItems RequestedItem[]
398+
399+
@@map("projects")
400+
}

api/src/core/entities/value-object.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export abstract class ValueObject<Props> {
2+
protected props: Props;
3+
4+
protected constructor(props: Props) {
5+
this.props = props;
6+
}
7+
8+
public equals(vo: ValueObject<unknown>) {
9+
if (vo === null || vo === undefined) {
10+
return false;
11+
}
12+
13+
if (vo.props === undefined) {
14+
return false;
15+
}
16+
17+
return JSON.stringify(vo.props) === JSON.stringify(this.props);
18+
}
19+
}

api/src/domain/entities/document.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { getCurrentDate } from "../../core/utils/get-current-date";
55
import { Field } from "./field";
66

77
export interface DocumentProps {
8+
id?: UniqueEntityID;
89
name: string;
910
fields: Field[];
1011
createdAt: Date;
@@ -43,4 +44,4 @@ export class Document extends Entity<DocumentProps> {
4344

4445
return document;
4546
}
46-
}
47+
}

api/src/domain/entities/opportunity.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { UniqueEntityID } from "../../core/entities/unique-entity-id";
33
import { Optional } from "../../core/types/optional";
44
import { getCurrentDate } from "../../core/utils/get-current-date";
55
import { RequiredDocument } from "./required-document";
6+
import { Document } from "./document";
67
import { Slug } from "./value-objects/slug";
78

89
export interface OpportunityProps {
@@ -18,6 +19,7 @@ export interface OpportunityProps {
1819
requiresCounterpart: boolean;
1920
counterpartPercentage?: number;
2021
requiredDocuments: RequiredDocument[];
22+
documents: Document[];
2123
isActive: boolean;
2224
releasedForAll?: boolean;
2325
type: string;
@@ -91,6 +93,10 @@ export class Opportunity extends Entity<OpportunityProps> {
9193
return this.props.requiredDocuments;
9294
}
9395

96+
get documents() {
97+
return this.props.documents;
98+
}
99+
94100
get typeId() {
95101
return this.props.typeId;
96102
}
@@ -128,4 +134,4 @@ export class Opportunity extends Entity<OpportunityProps> {
128134

129135
return opportunity;
130136
}
131-
}
137+
}

0 commit comments

Comments
 (0)