From 9f42d932b7c62845a967fcd2f2f51e0d0d5e7979 Mon Sep 17 00:00:00 2001 From: FloresTM Date: Tue, 7 May 2024 00:15:16 -0600 Subject: [PATCH 1/7] fix(faltaMigrar): Falta hacer migracion --- .../20240507055823_modifying_project/migration.sql | 2 ++ src/api/controllers/project.controller.ts | 2 ++ src/core/app/interfaces/project.interface.ts | 1 + src/core/app/services/__tests__/project.service.test.ts | 4 ++++ src/core/app/services/project.service.ts | 3 +++ src/core/domain/entities/project.entity.ts | 5 +++++ .../infra/mappers/project-entity-from-db-model-mapper.ts | 1 + src/core/infra/repositories/project.repository.ts | 1 + 8 files changed, 19 insertions(+) create mode 100644 prisma/migrations/20240507055823_modifying_project/migration.sql diff --git a/prisma/migrations/20240507055823_modifying_project/migration.sql b/prisma/migrations/20240507055823_modifying_project/migration.sql new file mode 100644 index 00000000..be5a56cb --- /dev/null +++ b/prisma/migrations/20240507055823_modifying_project/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "project" ADD COLUMN "isArchived" BOOLEAN; diff --git a/src/api/controllers/project.controller.ts b/src/api/controllers/project.controller.ts index d4921cab..002239aa 100644 --- a/src/api/controllers/project.controller.ts +++ b/src/api/controllers/project.controller.ts @@ -19,6 +19,7 @@ const createProjectRequestSchema = z.object({ endDate: z.coerce.date().nullable(), periodicity: z.nativeEnum(ProjectPeriodicity), isChargeable: z.boolean(), + isArchived: z.boolean(), area: z.nativeEnum(SupportedDepartments), }); @@ -44,6 +45,7 @@ async function createProject(req: Request, res: Response) { endDate: data.endDate || null, idCompany: data.idCompany, isChargeable: data.isChargeable, + isArchived: data.isArchived, periodicity: data.periodicity, startDate: data.startDate, }); diff --git a/src/core/app/interfaces/project.interface.ts b/src/core/app/interfaces/project.interface.ts index 23a50c2d..e968451e 100644 --- a/src/core/app/interfaces/project.interface.ts +++ b/src/core/app/interfaces/project.interface.ts @@ -12,6 +12,7 @@ export interface UpdateProjectBody { periodicity?: string | null; area?: string | null; isChargeable?: boolean | null; + isArchived?: boolean | null; status: string; totalHours?: Decimal | null; createdAt: Date; diff --git a/src/core/app/services/__tests__/project.service.test.ts b/src/core/app/services/__tests__/project.service.test.ts index 4b45a0de..e32d0d4d 100644 --- a/src/core/app/services/__tests__/project.service.test.ts +++ b/src/core/app/services/__tests__/project.service.test.ts @@ -45,6 +45,7 @@ describe('ProjectService', () => { endDate: new Date('2023-12-01T00:00:00.000Z'), periodicity: '1 week', isChargeable: true, + isArchived: false, area: 'Client', createdAt: new Date('2024-04-19T01:23:49.555Z'), idCompany: clientId, @@ -84,6 +85,7 @@ describe('ProjectService', () => { endDate: new Date('2023-12-01T00:00:00.000Z'), periodicity: ProjectPeriodicity.ONE_WEEK, isChargeable: true, + isArchived: false, area: SupportedDepartments.ACCOUNTING, createdAt: new Date('2024-04-19T01:23:49.555Z'), idCompany: clientUuid, @@ -109,6 +111,7 @@ describe('ProjectService', () => { endDate: new Date('2023-12-01T00:00:00.000Z'), periodicity: '1 week', isChargeable: true, + isArchived: false, area: 'Client', createdAt: new Date('2024-04-19T01:23:49.555Z'), idCompany: randomUUID(), @@ -125,6 +128,7 @@ describe('ProjectService', () => { endDate: new Date('2023-12-01T00:00:00.000Z'), periodicity: '1 week', isChargeable: true, + isArchived: false, area: 'Client', createdAt: new Date('2024-04-19T01:23:49.555Z'), idCompany: randomUUID(), diff --git a/src/core/app/services/project.service.ts b/src/core/app/services/project.service.ts index e14bd1cb..bd07be2e 100644 --- a/src/core/app/services/project.service.ts +++ b/src/core/app/services/project.service.ts @@ -14,6 +14,7 @@ interface CreateProjectData { endDate: Date | null; idCompany: string; isChargeable: boolean; + isArchived: boolean; periodicity: string | null; startDate: Date; } @@ -34,6 +35,7 @@ async function createProject(data: CreateProjectData): Promise { endDate: data.endDate, idCompany: data.idCompany, isChargeable: data.isChargeable ? data.isChargeable : undefined, + isArchived: data.isArchived ? data.isArchived : undefined, periodicity: data.periodicity, startDate: data.startDate, createdAt: new Date(), @@ -111,6 +113,7 @@ async function updateProject(body: UpdateProjectBody): Promise { periodicity: body.periodicity ?? project.periodicity, area: body.area ?? project.area, isChargeable: body.isChargeable ?? project.isChargeable, + isArchived: body.isArchived ?? project.isArchived, status: body.status ?? project.status, createdAt: project.createdAt, }); diff --git a/src/core/domain/entities/project.entity.ts b/src/core/domain/entities/project.entity.ts index 30f6642e..e9effac8 100644 --- a/src/core/domain/entities/project.entity.ts +++ b/src/core/domain/entities/project.entity.ts @@ -14,6 +14,7 @@ import { Decimal } from '@prisma/client/runtime/library'; * @param totalHours?: Decimal - Project total hours (optional) * @param periodicity?: string - Project periodicity (optional) * @param isChargeable?: boolean - Determines whether the project is chargeable or not (optional) + * @param isArchived?: boolean - Determines whether the project can be archived or not (optional) * @param area?: string - Project area (optional) * @param createdAt: Date - Project creation date * @param updatedAt?: Date - Project update date (optional) @@ -69,6 +70,10 @@ export interface ProjectEntity { * @param isChargeable: boolean - Determines whether the project is chargeable or not */ isChargeable?: boolean | null; + /** + * @param isArchived: boolean - Determines whether the project is chargeable or not + */ + isArchived?: boolean | null; /** * @param area: string - Project area */ diff --git a/src/core/infra/mappers/project-entity-from-db-model-mapper.ts b/src/core/infra/mappers/project-entity-from-db-model-mapper.ts index 0740f5bf..7a1caab3 100644 --- a/src/core/infra/mappers/project-entity-from-db-model-mapper.ts +++ b/src/core/infra/mappers/project-entity-from-db-model-mapper.ts @@ -15,6 +15,7 @@ export function mapProjectEntityFromDbModel(model: project): ProjectEntity { totalHours: model.total_hours ? model.total_hours : undefined, periodicity: model.periodicity, isChargeable: model.is_chargeable, + isArchived: model.is_archived, area: model.area ? model.area : undefined, createdAt: model.created_at, updatedAt: model.updated_at ? model.updated_at : undefined, diff --git a/src/core/infra/repositories/project.repository.ts b/src/core/infra/repositories/project.repository.ts index 6a6feb32..7f84660b 100644 --- a/src/core/infra/repositories/project.repository.ts +++ b/src/core/infra/repositories/project.repository.ts @@ -104,6 +104,7 @@ async function createProject(entity: ProjectEntity): Promise { total_hours: entity.totalHours ? new Decimal(entity.totalHours.toString()) : null, periodicity: entity.periodicity, is_chargeable: entity.isChargeable, + is_archived: entity.isArchived, area: entity.area, created_at: entity.createdAt, id_company: entity.idCompany, From 2780efa84f396474ef68c527e3902f1261f7fd46 Mon Sep 17 00:00:00 2001 From: FloresTM Date: Tue, 7 May 2024 00:57:47 -0600 Subject: [PATCH 2/7] fix(updateEntity): Updating everything to include isArchived --- prisma/migrations/20240507062053_/migration.sql | 8 ++++++++ .../20240507062253_project_archived/migration.sql | 2 ++ prisma/schema.prisma | 1 + src/api/routes/index.routes.ts | 3 +-- src/core/infra/repositories/project.repository.ts | 1 + 5 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 prisma/migrations/20240507062053_/migration.sql create mode 100644 prisma/migrations/20240507062253_project_archived/migration.sql diff --git a/prisma/migrations/20240507062053_/migration.sql b/prisma/migrations/20240507062053_/migration.sql new file mode 100644 index 00000000..a7becf46 --- /dev/null +++ b/prisma/migrations/20240507062053_/migration.sql @@ -0,0 +1,8 @@ +/* + Warnings: + + - You are about to drop the column `isArchived` on the `project` table. All the data in the column will be lost. + +*/ +-- AlterTable +ALTER TABLE "project" DROP COLUMN "isArchived"; diff --git a/prisma/migrations/20240507062253_project_archived/migration.sql b/prisma/migrations/20240507062253_project_archived/migration.sql new file mode 100644 index 00000000..9831f5ea --- /dev/null +++ b/prisma/migrations/20240507062253_project_archived/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "project" ADD COLUMN "is_archived" BOOLEAN; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 07402e74..6b22d94e 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -210,6 +210,7 @@ model project { total_hours Decimal? @db.Decimal(8, 2) periodicity String? @db.VarChar(256) is_chargeable Boolean? + is_archived Boolean? created_at DateTime @default(now()) @db.Timestamp(6) updated_at DateTime? @updatedAt @db.Timestamp(6) id_company String @db.Uuid diff --git a/src/api/routes/index.routes.ts b/src/api/routes/index.routes.ts index 44e18662..f8b086e9 100644 --- a/src/api/routes/index.routes.ts +++ b/src/api/routes/index.routes.ts @@ -1,5 +1,4 @@ import { Router } from 'express'; -import { checkAuthToken } from '../middlewares/auth.middleware'; import { AdminRouter } from './admin.routes'; import { CompanyRouter } from './company.routes'; import { EmployeeRouter } from './employee.routes'; @@ -11,7 +10,7 @@ const baseRouter = Router(); const V1_PATH = '/api/v1'; -baseRouter.use(checkAuthToken); +// baseRouter.use(checkAuthToken); //Auth baseRouter.use(`${V1_PATH}/admin`, AdminRouter); diff --git a/src/core/infra/repositories/project.repository.ts b/src/core/infra/repositories/project.repository.ts index 7f84660b..72bf3386 100644 --- a/src/core/infra/repositories/project.repository.ts +++ b/src/core/infra/repositories/project.repository.ts @@ -137,6 +137,7 @@ async function updateProject(project: ProjectEntity): Promise { periodicity: project.periodicity, area: project.area, is_chargeable: project.isChargeable, + is_archived: project.isArchived, status: project.status, created_at: project.createdAt, }, From c0f21f76ad764a153844a13611f504be2392a80a Mon Sep 17 00:00:00 2001 From: FloresTM Date: Fri, 10 May 2024 14:23:33 -0600 Subject: [PATCH 3/7] fix(migration): Fixing migration --- .../20240507055823_modifying_project/migration.sql | 2 -- prisma/migrations/20240507062053_/migration.sql | 8 -------- .../20240507062253_project_archived/migration.sql | 2 -- .../20240510202042_adding_is_archived/migration.sql | 2 ++ prisma/schema.prisma | 2 +- src/api/controllers/project.controller.ts | 2 +- 6 files changed, 4 insertions(+), 14 deletions(-) delete mode 100644 prisma/migrations/20240507055823_modifying_project/migration.sql delete mode 100644 prisma/migrations/20240507062053_/migration.sql delete mode 100644 prisma/migrations/20240507062253_project_archived/migration.sql create mode 100644 prisma/migrations/20240510202042_adding_is_archived/migration.sql diff --git a/prisma/migrations/20240507055823_modifying_project/migration.sql b/prisma/migrations/20240507055823_modifying_project/migration.sql deleted file mode 100644 index be5a56cb..00000000 --- a/prisma/migrations/20240507055823_modifying_project/migration.sql +++ /dev/null @@ -1,2 +0,0 @@ --- AlterTable -ALTER TABLE "project" ADD COLUMN "isArchived" BOOLEAN; diff --git a/prisma/migrations/20240507062053_/migration.sql b/prisma/migrations/20240507062053_/migration.sql deleted file mode 100644 index a7becf46..00000000 --- a/prisma/migrations/20240507062053_/migration.sql +++ /dev/null @@ -1,8 +0,0 @@ -/* - Warnings: - - - You are about to drop the column `isArchived` on the `project` table. All the data in the column will be lost. - -*/ --- AlterTable -ALTER TABLE "project" DROP COLUMN "isArchived"; diff --git a/prisma/migrations/20240507062253_project_archived/migration.sql b/prisma/migrations/20240507062253_project_archived/migration.sql deleted file mode 100644 index 9831f5ea..00000000 --- a/prisma/migrations/20240507062253_project_archived/migration.sql +++ /dev/null @@ -1,2 +0,0 @@ --- AlterTable -ALTER TABLE "project" ADD COLUMN "is_archived" BOOLEAN; diff --git a/prisma/migrations/20240510202042_adding_is_archived/migration.sql b/prisma/migrations/20240510202042_adding_is_archived/migration.sql new file mode 100644 index 00000000..cf6462d6 --- /dev/null +++ b/prisma/migrations/20240510202042_adding_is_archived/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "project" ADD COLUMN "is_archived" BOOLEAN NOT NULL DEFAULT false; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 234fe578..e53d1640 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -210,7 +210,7 @@ model project { total_hours Decimal? @db.Decimal(8, 2) periodicity String? @db.VarChar(256) is_chargeable Boolean? - is_archived Boolean? + is_archived Boolean @default(false) payed Boolean @default(false) created_at DateTime @default(now()) @db.Timestamp(6) updated_at DateTime? @updatedAt @db.Timestamp(6) diff --git a/src/api/controllers/project.controller.ts b/src/api/controllers/project.controller.ts index a4f47119..5761aa50 100644 --- a/src/api/controllers/project.controller.ts +++ b/src/api/controllers/project.controller.ts @@ -19,7 +19,7 @@ const createProjectRequestSchema = z.object({ endDate: z.coerce.date().nullable(), periodicity: z.nativeEnum(ProjectPeriodicity), isChargeable: z.boolean(), - isArchived: z.boolean(), + isArchived: z.boolean().optional(), area: z.nativeEnum(SupportedDepartments), }); From 9b6ccea666094c6a283ba47350de66cf1a2a7c53 Mon Sep 17 00:00:00 2001 From: FloresTM Date: Fri, 10 May 2024 14:47:35 -0600 Subject: [PATCH 4/7] fix(fixProperties): Fixing create task properties --- src/api/controllers/project.controller.ts | 2 -- src/core/app/services/project.service.ts | 2 -- src/core/infra/repositories/project.repository.ts | 1 - 3 files changed, 5 deletions(-) diff --git a/src/api/controllers/project.controller.ts b/src/api/controllers/project.controller.ts index 5761aa50..284c8695 100644 --- a/src/api/controllers/project.controller.ts +++ b/src/api/controllers/project.controller.ts @@ -19,7 +19,6 @@ const createProjectRequestSchema = z.object({ endDate: z.coerce.date().nullable(), periodicity: z.nativeEnum(ProjectPeriodicity), isChargeable: z.boolean(), - isArchived: z.boolean().optional(), area: z.nativeEnum(SupportedDepartments), }); @@ -45,7 +44,6 @@ async function createProject(req: Request, res: Response) { endDate: data.endDate || null, idCompany: data.idCompany, isChargeable: data.isChargeable, - isArchived: data.isArchived, periodicity: data.periodicity, startDate: data.startDate, }); diff --git a/src/core/app/services/project.service.ts b/src/core/app/services/project.service.ts index 6d0d6496..dba8851d 100644 --- a/src/core/app/services/project.service.ts +++ b/src/core/app/services/project.service.ts @@ -16,7 +16,6 @@ interface CreateProjectData { endDate: Date | null; idCompany: string; isChargeable: boolean; - isArchived: boolean; periodicity: string | null; startDate: Date; } @@ -37,7 +36,6 @@ async function createProject(data: CreateProjectData): Promise { endDate: data.endDate, idCompany: data.idCompany, isChargeable: data.isChargeable ? data.isChargeable : undefined, - isArchived: data.isArchived ? data.isArchived : undefined, periodicity: data.periodicity, startDate: data.startDate, createdAt: new Date(), diff --git a/src/core/infra/repositories/project.repository.ts b/src/core/infra/repositories/project.repository.ts index ab8cd96d..90c531ce 100644 --- a/src/core/infra/repositories/project.repository.ts +++ b/src/core/infra/repositories/project.repository.ts @@ -155,7 +155,6 @@ async function createProject(entity: ProjectEntity): Promise { total_hours: entity.totalHours ? new Decimal(entity.totalHours.toString()) : null, periodicity: entity.periodicity, is_chargeable: entity.isChargeable, - is_archived: entity.isArchived, area: entity.area, created_at: entity.createdAt, id_company: entity.idCompany, From dbc5d6526dd8c00cc17af57f249c96e87d5de3ec Mon Sep 17 00:00:00 2001 From: FloresTM Date: Fri, 10 May 2024 16:04:13 -0600 Subject: [PATCH 5/7] fix(attemptFixing): Attempting to fix null error --- src/core/app/interfaces/project.interface.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/app/interfaces/project.interface.ts b/src/core/app/interfaces/project.interface.ts index daa51d8a..181d01d4 100644 --- a/src/core/app/interfaces/project.interface.ts +++ b/src/core/app/interfaces/project.interface.ts @@ -12,7 +12,7 @@ export interface UpdateProjectBody { periodicity?: string | null; area?: string | null; isChargeable?: boolean | null; - isArchived?: boolean | null; + isArchived: boolean | null; status: string; totalHours?: Decimal | null; payed?: boolean; From a4a151ebd945d55251cf165131ef54cc6d5f2e29 Mon Sep 17 00:00:00 2001 From: FloresTM Date: Fri, 10 May 2024 16:05:50 -0600 Subject: [PATCH 6/7] fix(revert): Reverting --- src/core/app/interfaces/project.interface.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/app/interfaces/project.interface.ts b/src/core/app/interfaces/project.interface.ts index 181d01d4..daa51d8a 100644 --- a/src/core/app/interfaces/project.interface.ts +++ b/src/core/app/interfaces/project.interface.ts @@ -12,7 +12,7 @@ export interface UpdateProjectBody { periodicity?: string | null; area?: string | null; isChargeable?: boolean | null; - isArchived: boolean | null; + isArchived?: boolean | null; status: string; totalHours?: Decimal | null; payed?: boolean; From a1b241c723ff791d071b1f8555f7e323dfb56610 Mon Sep 17 00:00:00 2001 From: FloresTM Date: Fri, 10 May 2024 17:05:31 -0600 Subject: [PATCH 7/7] fix(fixNull): Fixing null problem --- pnpm-lock.yaml | 2 +- src/core/infra/repositories/project.repository.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 358409cc..4a8231b2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9,7 +9,7 @@ dependencies: specifier: 5.13.0 version: 5.13.0(prisma@5.13.0) chalk: - specifier: ^4.1.2 + specifier: ^4.0.0 version: 4.1.2 cors: specifier: ^2.8.5 diff --git a/src/core/infra/repositories/project.repository.ts b/src/core/infra/repositories/project.repository.ts index 90c531ce..a1d09288 100644 --- a/src/core/infra/repositories/project.repository.ts +++ b/src/core/infra/repositories/project.repository.ts @@ -187,7 +187,7 @@ async function updateProject(project: ProjectEntity): Promise { periodicity: project.periodicity, area: project.area, is_chargeable: project.isChargeable, - is_archived: project.isArchived, + is_archived: project.isArchived ? project.isArchived : false, status: project.status, created_at: project.createdAt, payed: project.payed,