diff --git a/docs/swagger/swagger-spec.json b/docs/swagger/swagger-spec.json index fe0a963..133f2d5 100644 --- a/docs/swagger/swagger-spec.json +++ b/docs/swagger/swagger-spec.json @@ -2441,7 +2441,7 @@ "example": 17.82, "description": "amount in $ for a refund" }, - "description": { + "comment": { "type": "string", "example": "Spent for mileage between A and B", "description": "explain`s why the expense was made" @@ -2463,7 +2463,7 @@ "bank_code_id", "date", "amount", - "description", + "comment", "is_approved", "supervisor_comment" ] @@ -2496,7 +2496,7 @@ "example": 17.82, "description": "amount in $ for a refund" }, - "description": { + "comment": { "type": "string", "example": "Spent for mileage between A and B", "description": "explain`s why the expense was made" diff --git a/prisma/migrations/20250909132655_refactor_description_to_comment_for_shifts_and_expenses/migration.sql b/prisma/migrations/20250909132655_refactor_description_to_comment_for_shifts_and_expenses/migration.sql new file mode 100644 index 0000000..7082aa6 --- /dev/null +++ b/prisma/migrations/20250909132655_refactor_description_to_comment_for_shifts_and_expenses/migration.sql @@ -0,0 +1,24 @@ +/* + Warnings: + + - You are about to drop the column `description` on the `expenses` table. All the data in the column will be lost. + - You are about to drop the column `description` on the `expenses_archive` table. All the data in the column will be lost. + - You are about to drop the column `description` on the `shifts` table. All the data in the column will be lost. + - You are about to drop the column `description` on the `shifts_archive` table. All the data in the column will be lost. + +*/ +-- AlterTable +ALTER TABLE "public"."expenses" DROP COLUMN "description", +ADD COLUMN "comment" TEXT; + +-- AlterTable +ALTER TABLE "public"."expenses_archive" DROP COLUMN "description", +ADD COLUMN "comment" TEXT; + +-- AlterTable +ALTER TABLE "public"."shifts" DROP COLUMN "description", +ADD COLUMN "comment" TEXT; + +-- AlterTable +ALTER TABLE "public"."shifts_archive" DROP COLUMN "description", +ADD COLUMN "comment" TEXT; diff --git a/prisma/mock-seeds-scripts/10-shifts.ts b/prisma/mock-seeds-scripts/10-shifts.ts index ebe8a2b..ab10340 100644 --- a/prisma/mock-seeds-scripts/10-shifts.ts +++ b/prisma/mock-seeds-scripts/10-shifts.ts @@ -181,7 +181,7 @@ async function main() { data: { timesheet_id: ts.id, bank_code_id: bcMorningId, - description: `Matin J${di + 1} (sem ${monday.toISOString().slice(0, 10)}) emp ${e.id} — ${bcMorningCode}`, + comment: `Matin J${di + 1} (sem ${monday.toISOString().slice(0, 10)}) emp ${e.id} — ${bcMorningCode}`, date, start_time: timeAt(startH, startM), end_time: timeAt(lunchStartHM.h, lunchStartHM.m), @@ -199,7 +199,7 @@ async function main() { data: { timesheet_id: ts.id, bank_code_id: bcAfternoonId, - description: `Après-midi J${di + 1} (sem ${monday.toISOString().slice(0, 10)}) emp ${e.id} — ${bcAfternoonCode}`, + comment: `Après-midi J${di + 1} (sem ${monday.toISOString().slice(0, 10)}) emp ${e.id} — ${bcAfternoonCode}`, date, start_time: timeAt(lunchEndHM.h, lunchEndHM.m), end_time: timeAt(finalEndHM.h, finalEndHM.m), @@ -214,7 +214,7 @@ async function main() { data: { timesheet_id: ts.id, bank_code_id: bcMap.get('G1')!, - description: `Fallback J${di + 1} (sem ${monday.toISOString().slice(0, 10)}) emp ${e.id} — G1`, + comment: `Fallback J${di + 1} (sem ${monday.toISOString().slice(0, 10)}) emp ${e.id} — G1`, date, start_time: timeAt(startH, startM), end_time: timeAt(fallbackEnd.h, fallbackEnd.m), diff --git a/prisma/mock-seeds-scripts/11-shifts-archive.ts b/prisma/mock-seeds-scripts/11-shifts-archive.ts index a6a78f8..1c3f5e8 100644 --- a/prisma/mock-seeds-scripts/11-shifts-archive.ts +++ b/prisma/mock-seeds-scripts/11-shifts-archive.ts @@ -37,7 +37,7 @@ async function main() { data: { timesheet_id: ts.id, bank_code_id: bc.id, - description: `Archived-era shift ${i + 1} for emp ${e.id}`, + comment: `Archived-era shift ${i + 1} for emp ${e.id}`, date, start_time: timeAt(startH, 0), end_time: timeAt(endH, 0), @@ -55,7 +55,7 @@ async function main() { shift_id: s.id, timesheet_id: s.timesheet_id, bank_code_id: s.bank_code_id, - description: s.description, + comment: s.comment, date: s.date, start_time: s.start_time, end_time: s.end_time, diff --git a/prisma/mock-seeds-scripts/12-expenses.ts b/prisma/mock-seeds-scripts/12-expenses.ts index 4318871..c0641a8 100644 --- a/prisma/mock-seeds-scripts/12-expenses.ts +++ b/prisma/mock-seeds-scripts/12-expenses.ts @@ -144,7 +144,7 @@ async function main() { date, amount, // string "xx.yy" (2 décimales exactes) attachement: null, - description: `Expense ${code} ${amount}$ (emp ${e.id})`, + comment: `Expense ${code} ${amount}$ (emp ${e.id})`, is_approved: Math.random() < 0.65, supervisor_comment: Math.random() < 0.25 ? 'OK' : null, }, diff --git a/prisma/mock-seeds-scripts/13-expenses-archive.ts b/prisma/mock-seeds-scripts/13-expenses-archive.ts index 8d9cc54..86d2c3b 100644 --- a/prisma/mock-seeds-scripts/13-expenses-archive.ts +++ b/prisma/mock-seeds-scripts/13-expenses-archive.ts @@ -33,7 +33,7 @@ async function main() { date: daysAgo(60 + i), amount: (20 + i * 3.5).toFixed(2), // ok: Decimal accepte string attachement: null, - description: `Old expense #${i + 1}`, + comment: `Old expense #${i + 1}`, is_approved: true, supervisor_comment: null, }, @@ -51,7 +51,7 @@ async function main() { date: e.date, amount: e.amount, attachement: e.attachement, - description: e.description, + comment: e.comment, is_approved: e.is_approved, supervisor_comment: e.supervisor_comment, }, diff --git a/prisma/schema.prisma b/prisma/schema.prisma index e9ef52c..d2c344c 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -177,7 +177,7 @@ model Shifts { timesheet_id Int bank_code BankCodes @relation("ShiftBankCodes", fields: [bank_code_id], references: [id]) bank_code_id Int - description String? + comment String? date DateTime @db.Date start_time DateTime @db.Time(0) end_time DateTime @db.Time(0) @@ -196,7 +196,7 @@ model ShiftsArchive { archive_at DateTime @default(now()) timesheet_id Int bank_code_id Int - description String? + comment String? date DateTime @db.Date start_time DateTime @db.Time(0) end_time DateTime @db.Time(0) @@ -227,7 +227,7 @@ model Expenses { date DateTime @db.Date amount Decimal @db.Money attachement String? - description String? + comment String? is_approved Boolean @default(false) supervisor_comment String? @@ -246,7 +246,7 @@ model ExpensesArchive { date DateTime @db.Date amount Decimal @db.Money attachement String? - description String? + comment String? is_approved Boolean supervisor_comment String? diff --git a/src/modules/expenses/dtos/create-expense.dto.ts b/src/modules/expenses/dtos/create-expense.dto.ts index 2958e88..b840a14 100644 --- a/src/modules/expenses/dtos/create-expense.dto.ts +++ b/src/modules/expenses/dtos/create-expense.dto.ts @@ -46,7 +46,7 @@ export class CreateExpenseDto { description:'explain`s why the expense was made' }) @IsString() - description?: string; + comment?: string; @ApiProperty({ example: 'DENIED, APPROUVED, PENDING, etc...', diff --git a/src/modules/expenses/dtos/search-expense.dto.ts b/src/modules/expenses/dtos/search-expense.dto.ts index 5058167..3eb7758 100644 --- a/src/modules/expenses/dtos/search-expense.dto.ts +++ b/src/modules/expenses/dtos/search-expense.dto.ts @@ -14,7 +14,7 @@ export class SearchExpensesDto { @IsOptional() @IsString() - description_contains?: string; + comment_contains?: string; @IsOptional() @IsDateString() diff --git a/src/modules/expenses/services/expenses-command.service.ts b/src/modules/expenses/services/expenses-command.service.ts index 2fc8777..7a8f722 100644 --- a/src/modules/expenses/services/expenses-command.service.ts +++ b/src/modules/expenses/services/expenses-command.service.ts @@ -22,17 +22,4 @@ export class ExpensesCommandService extends BaseApprovalService { this.updateApprovalWithTransaction(transaction, id, isApproved), ); } - - // deprecated since batch transaction are made with timesheets - // async updateManyWithTx( - // tx: Prisma.TransactionClient, - // ids: number[], - // isApproved: boolean, - // ): Promise { - // const { count } = await tx.expenses.updateMany({ - // where: { id: { in: ids } }, - // data: { is_approved: isApproved }, - // }); - // return count; - // } } \ No newline at end of file diff --git a/src/modules/expenses/services/expenses-query.service.ts b/src/modules/expenses/services/expenses-query.service.ts index b0d6191..42c9679 100644 --- a/src/modules/expenses/services/expenses-query.service.ts +++ b/src/modules/expenses/services/expenses-query.service.ts @@ -16,7 +16,7 @@ export class ExpensesQueryService { async create(dto: CreateExpenseDto): Promise { const { timesheet_id, bank_code_id, date, amount:rawAmount, - description, is_approved,supervisor_comment} = dto; + comment, is_approved,supervisor_comment} = dto; //fetches type and modifier @@ -37,7 +37,7 @@ export class ExpensesQueryService { } return this.prisma.expenses.create({ - data: { timesheet_id, bank_code_id, date, amount: final_amount, description, is_approved, supervisor_comment}, + data: { timesheet_id, bank_code_id, date, amount: final_amount, comment, is_approved, supervisor_comment}, include: { timesheet: { include: { employee: { include: { user: true }}}}, bank_code: true, }, @@ -66,7 +66,7 @@ export class ExpensesQueryService { async update(id: number, dto: UpdateExpenseDto): Promise { await this.findOne(id); const { timesheet_id, bank_code_id, date, amount, - description, is_approved, supervisor_comment} = dto; + comment, is_approved, supervisor_comment} = dto; return this.prisma.expenses.update({ where: { id }, data: { @@ -74,7 +74,7 @@ export class ExpensesQueryService { ...(bank_code_id !== undefined && { bank_code_id }), ...(date !== undefined && { date }), ...(amount !== undefined && { amount }), - ...(description !== undefined && { description }), + ...(comment !== undefined && { comment }), ...(is_approved !== undefined && { is_approved }), ...(supervisor_comment !== undefined && { supervisor_comment }), }, @@ -122,7 +122,7 @@ export class ExpensesQueryService { date: exp.date, amount: exp.amount, attachement: exp.attachement, - description: exp.description, + comment: exp.comment, is_approved: exp.is_approved, supervisor_comment: exp.supervisor_comment, })), diff --git a/src/modules/shifts/dtos/create-shift.dto.ts b/src/modules/shifts/dtos/create-shift.dto.ts index c3451d2..0fa93ab 100644 --- a/src/modules/shifts/dtos/create-shift.dto.ts +++ b/src/modules/shifts/dtos/create-shift.dto.ts @@ -48,5 +48,5 @@ export class CreateShiftDto { end_time: string; @IsString() - description: string; + comment: string; } diff --git a/src/modules/shifts/dtos/search-shift.dto.ts b/src/modules/shifts/dtos/search-shift.dto.ts index 4693a51..233a9b6 100644 --- a/src/modules/shifts/dtos/search-shift.dto.ts +++ b/src/modules/shifts/dtos/search-shift.dto.ts @@ -14,7 +14,7 @@ export class SearchShiftsDto { @IsOptional() @IsString() - description_contains?: string; + comment_contains?: string; @IsOptional() @IsDateString() diff --git a/src/modules/shifts/services/shifts-command.service.ts b/src/modules/shifts/services/shifts-command.service.ts index c3de439..0de643c 100644 --- a/src/modules/shifts/services/shifts-command.service.ts +++ b/src/modules/shifts/services/shifts-command.service.ts @@ -20,17 +20,4 @@ export class ShiftsCommandService extends BaseApprovalService { this.updateApprovalWithTransaction(transaction, id, is_approved), ); } - - // deprecated since batch transaction are made with timesheets - // async updateManyWithTx( - // tx: Prisma.TransactionClient, - // ids: number[], - // isApproved: boolean, - // ): Promise { - // const { count } = await tx.shifts.updateMany({ - // where: { id: { in: ids } }, - // data: { is_approved: isApproved }, - // }); - // return count; - // } } \ No newline at end of file diff --git a/src/modules/shifts/services/shifts-query.service.ts b/src/modules/shifts/services/shifts-query.service.ts index 0fb38ef..7bc6efe 100644 --- a/src/modules/shifts/services/shifts-query.service.ts +++ b/src/modules/shifts/services/shifts-query.service.ts @@ -29,11 +29,11 @@ export class ShiftsQueryService { ) {} async create(dto: CreateShiftDto): Promise { - const { timesheet_id, bank_code_id, date, start_time, end_time, description } = dto; + const { timesheet_id, bank_code_id, date, start_time, end_time, comment } = dto; //shift creation const shift = await this.prisma.shifts.create({ - data: { timesheet_id, bank_code_id, date, start_time, end_time, description }, + data: { timesheet_id, bank_code_id, date, start_time, end_time, comment }, include: { timesheet: { include: { employee: { include: { user: true } } } }, bank_code: true, }, @@ -93,7 +93,7 @@ export class ShiftsQueryService { async update(id: number, dto: UpdateShiftsDto): Promise { await this.findOne(id); - const { timesheet_id, bank_code_id, date,start_time,end_time, description} = dto; + const { timesheet_id, bank_code_id, date,start_time,end_time, comment} = dto; return this.prisma.shifts.update({ where: { id }, data: { @@ -102,7 +102,7 @@ export class ShiftsQueryService { ...(date !== undefined && { date }), ...(start_time !== undefined && { start_time }), ...(end_time !== undefined && { end_time }), - ...(description !== undefined && { description }), + ...(comment !== undefined && { comment }), }, include: { timesheet: { include: { employee: { include: { user: true } } } }, bank_code: true, @@ -243,7 +243,7 @@ export class ShiftsQueryService { shift_id: shift.id, timesheet_id: shift.timesheet_id, bank_code_id: shift.bank_code_id, - description: shift.description ?? undefined, + comment: shift.comment ?? undefined, date: shift.date, start_time: shift.start_time, end_time: shift.end_time, diff --git a/src/modules/timesheets/dtos/create-timesheet.dto.ts b/src/modules/timesheets/dtos/create-timesheet.dto.ts index 2e1c62a..1a53a08 100644 --- a/src/modules/timesheets/dtos/create-timesheet.dto.ts +++ b/src/modules/timesheets/dtos/create-timesheet.dto.ts @@ -22,7 +22,7 @@ export class CreateTimesheetDto { @IsOptional() @IsString() @Length(0,512) - description?: string; + comment?: string; } export class CreateWeekShiftsDto { diff --git a/src/modules/timesheets/dtos/overview-timesheet.dto.ts b/src/modules/timesheets/dtos/overview-timesheet.dto.ts index aaa7a95..95aad54 100644 --- a/src/modules/timesheets/dtos/overview-timesheet.dto.ts +++ b/src/modules/timesheets/dtos/overview-timesheet.dto.ts @@ -12,7 +12,7 @@ export class ShiftsDto { date: string; start_time: string; end_time: string; - description: string; + comment: string; is_approved: boolean; is_remote: boolean; } @@ -22,7 +22,7 @@ export class ExpensesDto { date: string; amount: number; km: number; - description: string; + comment: string; supervisor_comment: string; is_approved: boolean; } \ No newline at end of file diff --git a/src/modules/timesheets/services/timesheets-command.service.ts b/src/modules/timesheets/services/timesheets-command.service.ts index 5b58fa4..142fced 100644 --- a/src/modules/timesheets/services/timesheets-command.service.ts +++ b/src/modules/timesheets/services/timesheets-command.service.ts @@ -117,7 +117,7 @@ export class TimesheetsCommandService extends BaseApprovalService{ date: date, start_time: this.parseHHmm(shift.start_time), end_time: this.parseHHmm(shift.end_time), - description: shift.description ?? null, + comment: shift.comment ?? null, is_approved: false, is_remote: false, }, diff --git a/src/modules/timesheets/services/timesheets-query.service.ts b/src/modules/timesheets/services/timesheets-query.service.ts index 1849e16..e98a62c 100644 --- a/src/modules/timesheets/services/timesheets-query.service.ts +++ b/src/modules/timesheets/services/timesheets-query.service.ts @@ -161,7 +161,7 @@ export class TimesheetsQueryService { date: formatDateISO(sft.date), start_time: to_HH_mm(sft.start_time), end_time: to_HH_mm(sft.end_time), - description: sft.description ?? '', + comment: sft.comment ?? '', is_approved: sft.is_approved ?? false, is_remote: sft.is_remote ?? false, })); @@ -172,7 +172,7 @@ export class TimesheetsQueryService { date: formatDateISO(exp.date), amount: Number(exp.amount) || 0, km: 0, - description: exp.description ?? '', + comment: exp.comment ?? '', supervisor_comment: exp.supervisor_comment ?? '', is_approved: exp.is_approved ?? false, }));