fix(PrismaClient): fix a bug where transactionClients where instantiated with the wrong Prisma imports
This commit is contained in:
parent
d9f0362cb9
commit
b8157b78d1
|
|
@ -4,9 +4,6 @@ import { defineConfig } from 'prisma/config';
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
schema: "prisma/mariadb",
|
schema: "prisma/mariadb",
|
||||||
migrations: {
|
|
||||||
path: "prisma/mariadb/migrations",
|
|
||||||
},
|
|
||||||
datasource: {
|
datasource: {
|
||||||
url: process.env["DATABASE_URL_MARIADB"],
|
url: process.env["DATABASE_URL_MARIADB"],
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { Injectable, OnModuleInit, OnModuleDestroy } from '@nestjs/common';
|
import { Injectable, OnModuleInit, OnModuleDestroy } from '@nestjs/common';
|
||||||
import { adapterMariaDb } from 'prisma.config.mariadb';
|
import { adapterMariaDb } from 'prisma.config.mariadb';
|
||||||
import { PrismaClient } from '@prisma/client';
|
import { PrismaClient } from 'prisma/mariadb/generated/prisma/client/mariadb/client';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class PrismaMariaDbService extends PrismaClient implements OnModuleInit, OnModuleDestroy {
|
export class PrismaMariaDbService extends PrismaClient implements OnModuleInit, OnModuleDestroy {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { Injectable, OnModuleInit, OnModuleDestroy } from '@nestjs/common';
|
import { Injectable, OnModuleInit, OnModuleDestroy } from '@nestjs/common';
|
||||||
import { PrismaClient } from '@prisma/client';
|
|
||||||
import { adapterPostgres } from 'prisma.config.postgres';
|
import { adapterPostgres } from 'prisma.config.postgres';
|
||||||
|
import { PrismaClient } from 'prisma/postgres/generated/prisma/client/postgres/client';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class PrismaPostgresService extends PrismaClient implements OnModuleInit, OnModuleDestroy {
|
export class PrismaPostgresService extends PrismaClient implements OnModuleInit, OnModuleDestroy {
|
||||||
|
|
@ -8,15 +8,16 @@ export class PrismaPostgresService extends PrismaClient implements OnModuleInit,
|
||||||
readonly client: PrismaClient;
|
readonly client: PrismaClient;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super({ adapter: adapterPostgres }),
|
super({ adapter: adapterPostgres })
|
||||||
this.client = new PrismaClient({ adapter: adapterPostgres });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async onModuleInit() {
|
async onModuleInit() {
|
||||||
await this.client.$connect();
|
await this.$connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
async onModuleDestroy() {
|
async onModuleDestroy() {
|
||||||
await this.client.$disconnect();
|
await this.$disconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type TransactionClient = Parameters<Parameters<PrismaClient['$transaction']>[0]>[0];
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,21 @@
|
||||||
import { Injectable, OnModuleInit, OnModuleDestroy } from '@nestjs/common';
|
import { Injectable, OnModuleInit, OnModuleDestroy } from '@nestjs/common';
|
||||||
import { PrismaClient } from '@prisma/client';
|
|
||||||
import { adapterLegacy } from 'prisma.config.legacy';
|
import { adapterLegacy } from 'prisma.config.legacy';
|
||||||
|
import { PrismaClient } from 'prisma/prisma-legacy/generated/prisma/client/legacy/client';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class PrismaLegacyService implements OnModuleInit, OnModuleDestroy {
|
export class PrismaLegacyService extends PrismaClient implements OnModuleInit, OnModuleDestroy {
|
||||||
|
|
||||||
readonly client: PrismaClient;
|
readonly client: PrismaClient;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.client = new PrismaClient({adapter: adapterLegacy })
|
super({adapter: adapterLegacy})
|
||||||
}
|
}
|
||||||
|
|
||||||
async onModuleInit() {
|
async onModuleInit() {
|
||||||
await this.client.$connect();
|
await this.$connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
async onModuleDestroy() {
|
async onModuleDestroy() {
|
||||||
await this.client.$disconnect();
|
await this.$disconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import { NotFoundException } from "@nestjs/common";
|
import { NotFoundException } from "@nestjs/common";
|
||||||
import { Prisma, PrismaClient } from "@prisma/client";
|
|
||||||
import { PrismaClientKnownRequestError } from "@prisma/client/runtime/client";
|
import { PrismaClientKnownRequestError } from "@prisma/client/runtime/client";
|
||||||
import { PrismaPostgresService } from "prisma/postgres/prisma-postgres.service";
|
import { PrismaPostgresService, TransactionClient } from "prisma/postgres/prisma-postgres.service";
|
||||||
|
|
||||||
|
|
||||||
type UpdatableDelegate<T> = {
|
type UpdatableDelegate<T> = {
|
||||||
|
|
@ -18,7 +17,7 @@ export abstract class BaseApprovalService<T> {
|
||||||
//returns the corresponding Prisma delegate
|
//returns the corresponding Prisma delegate
|
||||||
protected abstract get delegate(): UpdatableDelegate<T>;
|
protected abstract get delegate(): UpdatableDelegate<T>;
|
||||||
|
|
||||||
protected abstract delegateFor(tx: Prisma.TransactionClient | PrismaClient): UpdatableDelegate<T>;
|
protected abstract delegateFor(tx: TransactionClient): UpdatableDelegate<T>;
|
||||||
|
|
||||||
//standard update Aproval
|
//standard update Aproval
|
||||||
async updateApproval(id: number, is_approved: boolean): Promise<T> {
|
async updateApproval(id: number, is_approved: boolean): Promise<T> {
|
||||||
|
|
@ -35,8 +34,7 @@ export abstract class BaseApprovalService<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//approval with transaction to avoid many requests
|
async updateApprovalWithTransaction(tx: TransactionClient, id: number, is_approved: boolean): Promise<T> {
|
||||||
async updateApprovalWithTransaction(tx: Prisma.TransactionClient, id: number, is_approved: boolean): Promise<T> {
|
|
||||||
try {
|
try {
|
||||||
return await this.delegateFor(tx).update({
|
return await this.delegateFor(tx).update({
|
||||||
where: { id },
|
where: { id },
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
import { Injectable } from "@nestjs/common";
|
import { Injectable } from "@nestjs/common";
|
||||||
import { PrismaClient } from "@prisma/client";
|
import { PrismaClient as MariadbClient } from "prisma/mariadb/generated/prisma/client/mariadb/client";
|
||||||
import { Result } from "src/common/errors/result-error.factory";
|
import { Result } from "src/common/errors/result-error.factory";
|
||||||
import { Account, AccountMemo } from "src/customer-support/accounts/account.dto";
|
import { Account, AccountMemo } from "src/customer-support/accounts/account.dto";
|
||||||
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AccountService {
|
export class AccountService {
|
||||||
constructor(private readonly prismaMariaDb: PrismaClient) { }
|
constructor(private readonly prismaMariaDb: MariadbClient) { }
|
||||||
|
|
||||||
findAllAccounts = async (): Promise<Result<Account[], string>> => {
|
findAllAccounts = async (): Promise<Result<Account[], string>> => {
|
||||||
const listOfAccounts: Account[] = [];
|
const listOfAccounts: Account[] = [];
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { Controller, Get, Query, Body, Post, Patch } from "@nestjs/common";
|
import { Controller, Get, Query, Body, Post, Patch } from "@nestjs/common";
|
||||||
import { Modules as ModulesEnum } from "@prisma/client";
|
import { Modules as ModulesEnum } from "prisma/postgres/generated/prisma/client/postgres/client";
|
||||||
import { ModuleAccessAllowed } from "src/common/decorators/modules-guard.decorators";
|
import { ModuleAccessAllowed } from "src/common/decorators/modules-guard.decorators";
|
||||||
import { Access } from "src/common/decorators/module-access.decorators";
|
import { Access } from "src/common/decorators/module-access.decorators";
|
||||||
import { Result } from "src/common/errors/result-error.factory";
|
import { Result } from "src/common/errors/result-error.factory";
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
import { Injectable } from "@nestjs/common";
|
import { Injectable } from "@nestjs/common";
|
||||||
import { Users } from "@prisma/client";
|
|
||||||
import { Result } from "src/common/errors/result-error.factory";
|
import { Result } from "src/common/errors/result-error.factory";
|
||||||
import { toDateFromString } from "src/common/utils/date-utils";
|
import { toDateFromString } from "src/common/utils/date-utils";
|
||||||
import { EmployeeDetailedDto } from "src/identity-and-account/employees/employee-detailed.dto";
|
import { EmployeeDetailedDto } from "src/identity-and-account/employees/employee-detailed.dto";
|
||||||
import { toCompanyCodeFromString } from "src/identity-and-account/employees/employee.utils";
|
import { toCompanyCodeFromString } from "src/identity-and-account/employees/employee.utils";
|
||||||
import { toBooleanFromString } from "src/identity-and-account/employees/services/employees-get.service";
|
import { toBooleanFromString } from "src/identity-and-account/employees/services/employees-get.service";
|
||||||
import { PrismaPostgresService } from "prisma/postgres/prisma-postgres.service";
|
import { PrismaPostgresService } from "prisma/postgres/prisma-postgres.service";
|
||||||
|
import { Users } from "prisma/postgres/generated/prisma/client/postgres/client";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class EmployeesCreateService {
|
export class EmployeesCreateService {
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ import { Result } from "src/common/errors/result-error.factory";
|
||||||
|
|
||||||
import { toStringFromCompanyCode } from "src/identity-and-account/employees/employee.utils";
|
import { toStringFromCompanyCode } from "src/identity-and-account/employees/employee.utils";
|
||||||
import { EmployeeDetailedDto } from "src/identity-and-account/employees/employee-detailed.dto";
|
import { EmployeeDetailedDto } from "src/identity-and-account/employees/employee-detailed.dto";
|
||||||
import { toKeysFromBoolean } from "src/common/utils/boolean-utils";
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class EmployeesGetService {
|
export class EmployeesGetService {
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,8 @@ import { toCompanyCodeFromString } from "src/identity-and-account/employees/empl
|
||||||
import { EmployeeDetailedUpsertDto } from "src/identity-and-account/employees/employee-detailed.dto";
|
import { EmployeeDetailedUpsertDto } from "src/identity-and-account/employees/employee-detailed.dto";
|
||||||
import { toBooleanFromString } from "src/identity-and-account/employees/services/employees-get.service";
|
import { toBooleanFromString } from "src/identity-and-account/employees/services/employees-get.service";
|
||||||
import { PaidTimeOffDto } from "src/time-and-attendance/paid-time-off/paid-time-off.dto";
|
import { PaidTimeOffDto } from "src/time-and-attendance/paid-time-off/paid-time-off.dto";
|
||||||
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class EmployeesUpdateService {
|
export class EmployeesUpdateService {
|
||||||
constructor(
|
constructor(
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { Controller, Get } from "@nestjs/common";
|
import { Controller, Get } from "@nestjs/common";
|
||||||
import { ModuleAccessAllowed } from "src/common/decorators/modules-guard.decorators";
|
import { ModuleAccessAllowed } from "src/common/decorators/modules-guard.decorators";
|
||||||
import { HomePageService } from "src/identity-and-account/help/help-page.service";
|
import { HomePageService } from "src/identity-and-account/help/help-page.service";
|
||||||
import { Modules as ModulesEnum } from "@prisma/client";
|
import { Modules as ModulesEnum } from "prisma/postgres/generated/prisma/client/postgres/client";
|
||||||
import { Access } from "src/common/decorators/module-access.decorators";
|
import { Access } from "src/common/decorators/module-access.decorators";
|
||||||
|
|
||||||
@Controller()
|
@Controller()
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import { PreferencesDto } from "./preferences.dto";
|
||||||
import { Result } from "src/common/errors/result-error.factory";
|
import { Result } from "src/common/errors/result-error.factory";
|
||||||
import { Access } from "src/common/decorators/module-access.decorators";
|
import { Access } from "src/common/decorators/module-access.decorators";
|
||||||
import { ModuleAccessAllowed } from "src/common/decorators/modules-guard.decorators";
|
import { ModuleAccessAllowed } from "src/common/decorators/modules-guard.decorators";
|
||||||
import { Modules as ModulesEnum } from "@prisma/client";
|
import { Modules as ModulesEnum } from "prisma/postgres/generated/prisma/client/postgres/client";
|
||||||
|
|
||||||
@Controller('preferences')
|
@Controller('preferences')
|
||||||
export class PreferencesController {
|
export class PreferencesController {
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import { ModuleAccess } from "src/identity-and-account/user-module-access/module
|
||||||
import { AccessGetService } from "src/identity-and-account/user-module-access/services/module-access-get.service";
|
import { AccessGetService } from "src/identity-and-account/user-module-access/services/module-access-get.service";
|
||||||
import { AccessUpdateService } from "src/identity-and-account/user-module-access/services/module-access-update.service";
|
import { AccessUpdateService } from "src/identity-and-account/user-module-access/services/module-access-update.service";
|
||||||
import { ModuleAccessAllowed } from "src/common/decorators/modules-guard.decorators";
|
import { ModuleAccessAllowed } from "src/common/decorators/modules-guard.decorators";
|
||||||
import { Modules as ModulesEnum } from ".prisma/client";
|
import { Modules as ModulesEnum } from "prisma/postgres/generated/prisma/client/postgres/client";
|
||||||
|
|
||||||
@Controller('module_access')
|
@Controller('module_access')
|
||||||
export class ModuleAccessController {
|
export class ModuleAccessController {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||||
import { Modules, Users } from '@prisma/client';
|
import { Modules, Users } from 'prisma/postgres/generated/prisma/client/postgres/client';
|
||||||
import { toKeysFromBoolean } from 'src/common/utils/boolean-utils';
|
import { toKeysFromBoolean } from 'src/common/utils/boolean-utils';
|
||||||
import { PrismaPostgresService } from 'prisma/postgres/prisma-postgres.service';
|
import { PrismaPostgresService } from 'prisma/postgres/prisma-postgres.service';
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Modules, Roles } from "@prisma/client";
|
import { Modules, Roles } from "prisma/postgres/generated/prisma/client/postgres/client";
|
||||||
import { IsArray, IsEmail, IsEnum, IsString } from "class-validator";
|
import { IsArray, IsEmail, IsEnum, IsString } from "class-validator";
|
||||||
|
|
||||||
export class UserDto {
|
export class UserDto {
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,13 @@
|
||||||
import 'dotenv/config';
|
import 'dotenv/config';
|
||||||
import { Worker } from 'bullmq';
|
import { Worker } from 'bullmq';
|
||||||
import sharp from 'sharp';
|
import sharp from 'sharp';
|
||||||
import { PrismaClient } from '@prisma/client';
|
import { PrismaClient } from 'prisma/postgres/generated/prisma/client/postgres/client';
|
||||||
import * as path from 'node:path';
|
import * as path from 'node:path';
|
||||||
import { promises as fsp } from 'node:fs';
|
import { promises as fsp } from 'node:fs';
|
||||||
import { resolveAttachmentsRoot } from 'src/time-and-attendance/attachments/config/attachment.config';
|
import { resolveAttachmentsRoot } from 'src/time-and-attendance/attachments/config/attachment.config';
|
||||||
|
import { adapterPostgres } from 'prisma.config.postgres';
|
||||||
|
|
||||||
const prisma = new PrismaClient();
|
const prisma = new PrismaClient({ adapter: adapterPostgres });
|
||||||
const q_name = `${process.env.BULL_PREFIX || 'attachments'}:variants`;
|
const q_name = `${process.env.BULL_PREFIX || 'attachments'}:variants`;
|
||||||
const root = resolveAttachmentsRoot();
|
const root = resolveAttachmentsRoot();
|
||||||
|
|
||||||
|
|
@ -50,5 +51,6 @@ new Worker(q_name, async job => {
|
||||||
} as any);
|
} as any);
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
connection: { url: process.env.REDIS_URL }, concurrency: 3 }
|
connection: { url: process.env.REDIS_URL }, concurrency: 3
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { Body, Controller, Get, Param, ParseIntPipe, Patch, Post } from "@nestjs/common";
|
import { Body, Controller, Get, Param, ParseIntPipe, Patch, Post } from "@nestjs/common";
|
||||||
import { ModuleAccessAllowed } from "src/common/decorators/modules-guard.decorators";
|
import { ModuleAccessAllowed } from "src/common/decorators/modules-guard.decorators";
|
||||||
import { Result } from "src/common/errors/result-error.factory";
|
import { Result } from "src/common/errors/result-error.factory";
|
||||||
import { Modules as ModulesEnum, Prisma } from ".prisma/client";
|
import { Modules as ModulesEnum, Prisma } from "prisma/postgres/generated/prisma/client/postgres/client";
|
||||||
import { BankCodesService } from "src/time-and-attendance/bank-codes/bank-codes.service";
|
import { BankCodesService } from "src/time-and-attendance/bank-codes/bank-codes.service";
|
||||||
|
|
||||||
@Controller('bank-codes')
|
@Controller('bank-codes')
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { Injectable } from "@nestjs/common";
|
import { Injectable } from "@nestjs/common";
|
||||||
import { Prisma } from "@prisma/client";
|
import { Prisma } from "prisma/postgres/generated/prisma/client/postgres/client";
|
||||||
import { PrismaPostgresService } from "prisma/postgres/prisma-postgres.service";
|
import { PrismaPostgresService } from "prisma/postgres/prisma-postgres.service";
|
||||||
import { Result } from "src/common/errors/result-error.factory";
|
import { Result } from "src/common/errors/result-error.factory";
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { Prisma, PrismaClient } from '@prisma/client';
|
import { Prisma, PrismaClient } from 'prisma/postgres/generated/prisma/client/postgres/client';
|
||||||
import { getWeekStart, getWeekEnd, computeHours } from 'src/common/utils/date-utils';
|
import { getWeekStart, getWeekEnd, computeHours } from 'src/common/utils/date-utils';
|
||||||
import { PrismaPostgresService } from 'prisma/postgres/prisma-postgres.service';
|
import { PrismaPostgresService } from 'prisma/postgres/prisma-postgres.service';
|
||||||
import { DAILY_LIMIT_HOURS, WEEKLY_LIMIT_HOURS } from 'src/common/utils/constants.utils';
|
import { DAILY_LIMIT_HOURS, WEEKLY_LIMIT_HOURS } from 'src/common/utils/constants.utils';
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { Injectable } from "@nestjs/common";
|
import { Injectable } from "@nestjs/common";
|
||||||
import { Prisma } from "@prisma/client";
|
import { Prisma } from "prisma/postgres/generated/prisma/client/postgres/client";
|
||||||
import { PrismaPostgresService } from "prisma/postgres/prisma-postgres.service";
|
import { PrismaPostgresService } from "prisma/postgres/prisma-postgres.service";
|
||||||
import { Result } from "src/common/errors/result-error.factory";
|
import { Result } from "src/common/errors/result-error.factory";
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import { Controller, Post, Param, Body, Patch, Delete, Req, UnauthorizedExceptio
|
||||||
import { ExpenseDto } from "src/time-and-attendance/expenses/expense-create.dto";
|
import { ExpenseDto } from "src/time-and-attendance/expenses/expense-create.dto";
|
||||||
import { Result } from "src/common/errors/result-error.factory";
|
import { Result } from "src/common/errors/result-error.factory";
|
||||||
import { ModuleAccessAllowed } from "src/common/decorators/modules-guard.decorators";
|
import { ModuleAccessAllowed } from "src/common/decorators/modules-guard.decorators";
|
||||||
import { Modules as ModulesEnum } from ".prisma/client";
|
import { Modules as ModulesEnum } from "prisma/postgres/generated/prisma/client/postgres/client";
|
||||||
import { Access } from "src/common/decorators/module-access.decorators";
|
import { Access } from "src/common/decorators/module-access.decorators";
|
||||||
import { ExpenseUpdateService } from "src/time-and-attendance/expenses/services/expense-update.service";
|
import { ExpenseUpdateService } from "src/time-and-attendance/expenses/services/expense-update.service";
|
||||||
import { ExpenseCreateService } from "src/time-and-attendance/expenses/services/expense-create.service";
|
import { ExpenseCreateService } from "src/time-and-attendance/expenses/services/expense-create.service";
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { Controller, Get, Param, Query, Res } from "@nestjs/common";
|
import { Controller, Get, Param, Query, Res } from "@nestjs/common";
|
||||||
import { CsvExportService } from "./services/csv-exports.service";
|
import { CsvExportService } from "./services/csv-exports.service";
|
||||||
import { ModuleAccessAllowed } from "src/common/decorators/modules-guard.decorators";
|
import { ModuleAccessAllowed } from "src/common/decorators/modules-guard.decorators";
|
||||||
import { Modules as ModulesEnum } from "@prisma/client";
|
import { Modules as ModulesEnum } from "prisma/postgres/generated/prisma/client/postgres/client";
|
||||||
import { Response } from "express";
|
import { Response } from "express";
|
||||||
import { CsvGeneratorService } from "src/time-and-attendance/exports/services/csv-builder.service";
|
import { CsvGeneratorService } from "src/time-and-attendance/exports/services/csv-builder.service";
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import { PayPeriodsQueryService } from "./services/pay-periods-query.service";
|
||||||
import { PayPeriodsCommandService } from "./services/pay-periods-command.service";
|
import { PayPeriodsCommandService } from "./services/pay-periods-command.service";
|
||||||
import { Result } from "src/common/errors/result-error.factory";
|
import { Result } from "src/common/errors/result-error.factory";
|
||||||
import { ModuleAccessAllowed } from "src/common/decorators/modules-guard.decorators";
|
import { ModuleAccessAllowed } from "src/common/decorators/modules-guard.decorators";
|
||||||
import { Modules as ModulesEnum } from "@prisma/client";
|
import { Modules as ModulesEnum } from "prisma/postgres/generated/prisma/client/postgres/client";
|
||||||
import { GetOverviewService } from "src/time-and-attendance/pay-period/services/pay-periods-build-overview.service";
|
import { GetOverviewService } from "src/time-and-attendance/pay-period/services/pay-periods-build-overview.service";
|
||||||
import { map, Observable } from "rxjs";
|
import { map, Observable } from "rxjs";
|
||||||
import { PayPeriodEventService } from "src/time-and-attendance/pay-period/services/pay-period-event.service";
|
import { PayPeriodEventService } from "src/time-and-attendance/pay-period/services/pay-period-event.service";
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { PayPeriods } from "@prisma/client";
|
import { PayPeriods } from "prisma/postgres/generated/prisma/client/postgres/client";
|
||||||
import { PayPeriodDto } from "src/time-and-attendance/pay-period/dtos/overview-pay-period.dto";
|
import { PayPeriodDto } from "src/time-and-attendance/pay-period/dtos/overview-pay-period.dto";
|
||||||
|
|
||||||
const toDateString = (date: Date) => date.toISOString().slice(0, 10); // "YYYY-MM-DD"
|
const toDateString = (date: Date) => date.toISOString().slice(0, 10); // "YYYY-MM-DD"
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import { Injectable } from "@nestjs/common";
|
||||||
import { PrismaPostgresService } from "prisma/postgres/prisma-postgres.service";
|
import { PrismaPostgresService } from "prisma/postgres/prisma-postgres.service";
|
||||||
import { Result } from "src/common/errors/result-error.factory";
|
import { Result } from "src/common/errors/result-error.factory";
|
||||||
import { EmailToIdResolver } from "src/common/mappers/email-id.mapper";
|
import { EmailToIdResolver } from "src/common/mappers/email-id.mapper";
|
||||||
import { Prisma } from "@prisma/client";
|
import { Prisma } from "prisma/postgres/generated/prisma/client/postgres/client";
|
||||||
|
|
||||||
|
|
||||||
//change promise to return result pattern
|
//change promise to return result pattern
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import { SchedulePresetsGetService } from "src/time-and-attendance/schedule-pres
|
||||||
import { SchedulePresetsDto } from "src/time-and-attendance/schedule-presets/schedule-presets.dto";
|
import { SchedulePresetsDto } from "src/time-and-attendance/schedule-presets/schedule-presets.dto";
|
||||||
|
|
||||||
import { ModuleAccessAllowed } from "src/common/decorators/modules-guard.decorators";
|
import { ModuleAccessAllowed } from "src/common/decorators/modules-guard.decorators";
|
||||||
import { Modules as ModulesEnum } from "@prisma/client";
|
import { Modules as ModulesEnum } from "prisma/postgres/generated/prisma/client/postgres/client";
|
||||||
import { Access } from "src/common/decorators/module-access.decorators";
|
import { Access } from "src/common/decorators/module-access.decorators";
|
||||||
import { SchedulePresetsApplyService } from "src/time-and-attendance/schedule-presets/services/schedule-presets-apply.service";
|
import { SchedulePresetsApplyService } from "src/time-and-attendance/schedule-presets/services/schedule-presets-apply.service";
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Weekday } from "@prisma/client";
|
import { Weekday } from "prisma/postgres/generated/prisma/client/postgres/client";
|
||||||
import { ArrayMinSize, IsArray, IsBoolean, IsEnum, IsInt, IsOptional, IsString, Matches} from "class-validator";
|
import { ArrayMinSize, IsArray, IsBoolean, IsEnum, IsInt, IsOptional, IsString, Matches} from "class-validator";
|
||||||
import { HH_MM_REGEX } from "src/common/utils/constants.utils";
|
import { HH_MM_REGEX } from "src/common/utils/constants.utils";
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { Body, Controller, Delete, Param, Patch, Post } from "@nestjs/common";
|
import { Body, Controller, Delete, Param, Patch, Post } from "@nestjs/common";
|
||||||
import { Modules as ModulesEnum } from "@prisma/client";
|
import { Modules as ModulesEnum } from "prisma/postgres/generated/prisma/client/postgres/client";
|
||||||
|
|
||||||
import { ShiftDto } from "src/time-and-attendance/shifts/shift.dto";
|
import { ShiftDto } from "src/time-and-attendance/shifts/shift.dto";
|
||||||
import { ShiftsCreateService } from "src/time-and-attendance/shifts/services/shifts-create.service";
|
import { ShiftsCreateService } from "src/time-and-attendance/shifts/services/shifts-create.service";
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,12 @@
|
||||||
import { Injectable, NotFoundException } from "@nestjs/common";
|
import { Injectable, NotFoundException } from "@nestjs/common";
|
||||||
import { Prisma, PrismaClient, Timesheets } from "@prisma/client";
|
import { Prisma, Timesheets } from "prisma/postgres/generated/prisma/client/postgres/client";
|
||||||
import { PrismaPostgresService } from "prisma/postgres/prisma-postgres.service";
|
import { PrismaPostgresService, TransactionClient } from "prisma/postgres/prisma-postgres.service";
|
||||||
import { BaseApprovalService } from "src/common/shared/base-approval.service";
|
import { BaseApprovalService } from "src/common/shared/base-approval.service";
|
||||||
import { timesheet_select } from "src/time-and-attendance/utils/selects.utils";
|
import { timesheet_select } from "src/time-and-attendance/utils/selects.utils";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class TimesheetApprovalService extends BaseApprovalService<Timesheets>{
|
export class TimesheetApprovalService extends BaseApprovalService<Timesheets>{
|
||||||
constructor(
|
constructor(
|
||||||
|
|
@ -17,7 +20,7 @@ import { timesheet_select } from "src/time-and-attendance/utils/selects.utils";
|
||||||
return this.prisma.client.timesheets;
|
return this.prisma.client.timesheets;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected delegateFor(tx: Prisma.TransactionClient | PrismaClient) {
|
protected delegateFor(tx: TransactionClient) {
|
||||||
return tx.timesheets;
|
return tx.timesheets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -27,13 +30,13 @@ import { timesheet_select } from "src/time-and-attendance/utils/selects.utils";
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async cascadeApprovalWithtx(tx: Prisma.TransactionClient, timesheet_id: number, is_approved: boolean): Promise<Timesheets> {
|
async cascadeApprovalWithtx(tx: TransactionClient, timesheet_id: number, is_approved: boolean): Promise<Timesheets> {
|
||||||
const timesheet = await this.updateApprovalWithTransaction(tx, timesheet_id, is_approved);
|
const timesheet = await this.updateApprovalWithTransaction(tx, timesheet_id, is_approved);
|
||||||
await tx.shifts.updateMany({
|
await tx.shifts.updateMany({
|
||||||
where: { timesheet_id: timesheet_id },
|
where: { timesheet_id: timesheet_id },
|
||||||
data: { is_approved: is_approved },
|
data: { is_approved: is_approved },
|
||||||
});
|
});
|
||||||
await tx.expenses.updateManyAndReturn({
|
await tx.expenses.updateMany({
|
||||||
where: { timesheet_id: timesheet_id },
|
where: { timesheet_id: timesheet_id },
|
||||||
data: { is_approved: is_approved },
|
data: { is_approved: is_approved },
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import { Body, Controller, Get, Param, ParseBoolPipe, ParseIntPipe, Patch, Query
|
||||||
import { GetTimesheetsOverviewService } from "src/time-and-attendance/timesheets/services/timesheet-employee-overview.service";
|
import { GetTimesheetsOverviewService } from "src/time-and-attendance/timesheets/services/timesheet-employee-overview.service";
|
||||||
import { TimesheetApprovalService } from "src/time-and-attendance/timesheets/services/timesheet-approval.service";
|
import { TimesheetApprovalService } from "src/time-and-attendance/timesheets/services/timesheet-approval.service";
|
||||||
import { ModuleAccessAllowed } from "src/common/decorators/modules-guard.decorators";
|
import { ModuleAccessAllowed } from "src/common/decorators/modules-guard.decorators";
|
||||||
import { Modules as ModulesEnum } from "@prisma/client";
|
import { Modules as ModulesEnum } from "prisma/postgres/generated/prisma/client/postgres/client";
|
||||||
import { Access } from "src/common/decorators/module-access.decorators";
|
import { Access } from "src/common/decorators/module-access.decorators";
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
import { Prisma } from "@prisma/client";
|
import { Prisma } from "prisma/postgres/generated/prisma/client/postgres/client";
|
||||||
import { toDateFromString, sevenDaysFrom, toStringFromDate, toHHmmFromDate } from "src/common/utils/date-utils";
|
import { toDateFromString, sevenDaysFrom, toStringFromDate, toHHmmFromDate } from "src/common/utils/date-utils";
|
||||||
import { Timesheet } from "src/time-and-attendance/timesheets/timesheet.dto";
|
import { Timesheet } from "src/time-and-attendance/timesheets/timesheet.dto";
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Prisma } from "@prisma/client";
|
import { Prisma } from "prisma/postgres/generated/prisma/client/postgres/client";
|
||||||
|
|
||||||
|
|
||||||
export const expense_select = {
|
export const expense_select = {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user