refacto: naming uuid to uid
This commit is contained in:
parent
f9dbf38dac
commit
eab04fb12e
@ -22,10 +22,9 @@
|
|||||||
"start": "tsc && node ./dist/entries/App.js",
|
"start": "tsc && node ./dist/entries/App.js",
|
||||||
"api:start": "npm run migrate && npm run start",
|
"api:start": "npm run migrate && npm run start",
|
||||||
"dev": "nodemon -V",
|
"dev": "nodemon -V",
|
||||||
"build:test": "tsc && mocha ./dist/entries/Test.js",
|
|
||||||
"format": "prettier --write src",
|
"format": "prettier --write src",
|
||||||
"migrate": "npx prisma migrate deploy",
|
|
||||||
"migrate:test": "dotenv -e .env.test -- npx prisma migrate deploy",
|
"migrate:test": "dotenv -e .env.test -- npx prisma migrate deploy",
|
||||||
|
"migrate": "npx prisma migrate deploy",
|
||||||
"docker:up:test": "docker-compose -f docker-compose-test.yml up -d",
|
"docker:up:test": "docker-compose -f docker-compose-test.yml up -d",
|
||||||
"docker:down:test": "docker-compose down",
|
"docker:down:test": "docker-compose down",
|
||||||
"test": "tsc && npm run docker:up:test && npm run migrate:test && dotenv -e .env.test -- jest -i --verbose ./dist/test/* && npm run docker:down:test"
|
"test": "tsc && npm run docker:up:test && npm run migrate:test && dotenv -e .env.test -- jest -i --verbose ./dist/test/* && npm run docker:down:test"
|
||||||
|
@ -3,11 +3,11 @@ import { Controller, Get, Post, Put } from "@ControllerPattern/index";
|
|||||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||||
import CustomersService from "@Services/super-admin/CustomersService/CustomersService";
|
import CustomersService from "@Services/super-admin/CustomersService/CustomersService";
|
||||||
import { Service } from "typedi";
|
import { Service } from "typedi";
|
||||||
import ObjectHydrate from "@Common/helpers/ObjectHydrate";
|
|
||||||
import { Customer } from "le-coffre-resources/dist/SuperAdmin";
|
import { Customer } from "le-coffre-resources/dist/SuperAdmin";
|
||||||
import { Customers } from "@prisma/client";
|
import { Customers } from "@prisma/client";
|
||||||
import { validateOrReject } from "class-validator";
|
import { validateOrReject } from "class-validator";
|
||||||
|
|
||||||
|
|
||||||
@Controller()
|
@Controller()
|
||||||
@Service()
|
@Service()
|
||||||
export default class CustomersController extends ApiController {
|
export default class CustomersController extends ApiController {
|
||||||
@ -25,10 +25,10 @@ export default class CustomersController extends ApiController {
|
|||||||
const query = JSON.parse(req.query["q"] as string);
|
const query = JSON.parse(req.query["q"] as string);
|
||||||
|
|
||||||
//call service to get prisma entity
|
//call service to get prisma entity
|
||||||
const customersEntity: Customers[] = await this.customersService.get(query);
|
const customersEntity = await this.customersService.get(query);
|
||||||
|
|
||||||
//Hydrate ressource with prisma entity
|
//Hydrate ressource with prisma entity
|
||||||
const customers = ObjectHydrate.map<Customer>(Customer, customersEntity, { strategy: "exposeAll" });
|
const customers = Customer.map<Customer>(Customer, customersEntity, { strategy: "excludeAll" });
|
||||||
|
|
||||||
//success
|
//success
|
||||||
this.httpSuccess(response, customers);
|
this.httpSuccess(response, customers);
|
||||||
@ -46,7 +46,7 @@ export default class CustomersController extends ApiController {
|
|||||||
try {
|
try {
|
||||||
//init IUser resource with request body values
|
//init IUser resource with request body values
|
||||||
const customerEntity = new Customer();
|
const customerEntity = new Customer();
|
||||||
ObjectHydrate.hydrate(customerEntity, req.body);
|
Customer.hydrate(customerEntity, req.body);
|
||||||
|
|
||||||
//validate user
|
//validate user
|
||||||
await validateOrReject(customerEntity, { groups: ["createCustomer"], forbidUnknownValues: false});
|
await validateOrReject(customerEntity, { groups: ["createCustomer"], forbidUnknownValues: false});
|
||||||
@ -55,8 +55,8 @@ export default class CustomersController extends ApiController {
|
|||||||
const prismaEntityCreated = await this.customersService.create(customerEntity);
|
const prismaEntityCreated = await this.customersService.create(customerEntity);
|
||||||
|
|
||||||
//Hydrate ressource with prisma entity
|
//Hydrate ressource with prisma entity
|
||||||
const customerEntityCreated = ObjectHydrate.hydrate<Customer>(new Customer(), prismaEntityCreated, {
|
const customerEntityCreated = Customer.hydrate<Customer>(prismaEntityCreated, {
|
||||||
strategy: "exposeAll",
|
strategy: "excludeAll",
|
||||||
});
|
});
|
||||||
|
|
||||||
//success
|
//success
|
||||||
@ -79,7 +79,7 @@ export default class CustomersController extends ApiController {
|
|||||||
}
|
}
|
||||||
//init IUser resource with request body values
|
//init IUser resource with request body values
|
||||||
const customerEntity = new Customer();
|
const customerEntity = new Customer();
|
||||||
ObjectHydrate.hydrate(customerEntity, req.body);
|
Customer.hydrate(customerEntity, req.body);
|
||||||
//validate user
|
//validate user
|
||||||
await validateOrReject(customerEntity, { groups: ["updateCustomer"] , forbidUnknownValues: false});
|
await validateOrReject(customerEntity, { groups: ["updateCustomer"] , forbidUnknownValues: false});
|
||||||
|
|
||||||
@ -87,7 +87,7 @@ export default class CustomersController extends ApiController {
|
|||||||
const prismaEntityUpdated = await this.customersService.update(uid, customerEntity);
|
const prismaEntityUpdated = await this.customersService.update(uid, customerEntity);
|
||||||
|
|
||||||
//Hydrate ressource with prisma entity
|
//Hydrate ressource with prisma entity
|
||||||
const customerEntityUpdated = ObjectHydrate.hydrate<Customer>(new Customer(), prismaEntityUpdated, {
|
const customerEntityUpdated = Customer.hydrate<Customer>(prismaEntityUpdated, {
|
||||||
strategy: "exposeAll",
|
strategy: "exposeAll",
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -121,7 +121,7 @@ export default class CustomersController extends ApiController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Hydrate ressource with prisma entity
|
//Hydrate ressource with prisma entity
|
||||||
const customer = ObjectHydrate.hydrate<Customer>(new Customer(), customerEntity, { strategy: "exposeAll" });
|
const customer = Customer.hydrate<Customer>(customerEntity, { strategy: "exposeAll" });
|
||||||
|
|
||||||
//success
|
//success
|
||||||
this.httpSuccess(response, customer);
|
this.httpSuccess(response, customer);
|
||||||
|
@ -7,7 +7,6 @@ import ObjectHydrate from "@Common/helpers/ObjectHydrate";
|
|||||||
import { validateOrReject } from "class-validator";
|
import { validateOrReject } from "class-validator";
|
||||||
import User from "le-coffre-resources/dist/Notary";
|
import User from "le-coffre-resources/dist/Notary";
|
||||||
import { Users } from "@prisma/client";
|
import { Users } from "@prisma/client";
|
||||||
import { plainToInstance } from "class-transformer";
|
|
||||||
|
|
||||||
@Controller()
|
@Controller()
|
||||||
@Service()
|
@Service()
|
||||||
@ -29,10 +28,7 @@ export default class UsersController extends ApiController {
|
|||||||
const usersEntity: Users[] = await this.usersService.get(query);
|
const usersEntity: Users[] = await this.usersService.get(query);
|
||||||
|
|
||||||
//Hydrate ressource with prisma entity
|
//Hydrate ressource with prisma entity
|
||||||
const users = plainToInstance<User, Users[]>(User, usersEntity, {
|
const users = User.map<User>(User, usersEntity, {excludeExtraneousValues: true})
|
||||||
enableImplicitConversion: true,
|
|
||||||
excludeExtraneousValues: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
//success
|
//success
|
||||||
this.httpSuccess(response, users);
|
this.httpSuccess(response, users);
|
||||||
|
@ -443,3 +443,4 @@ ALTER TABLE "deed_type_has_document_types" ADD CONSTRAINT "deed_type_has_documen
|
|||||||
|
|
||||||
-- AddForeignKey
|
-- AddForeignKey
|
||||||
ALTER TABLE "deed_type_has_document_types" ADD CONSTRAINT "deed_type_has_document_types_deed_type_uid_fkey" FOREIGN KEY ("deed_type_uid") REFERENCES "deed_types"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
ALTER TABLE "deed_type_has_document_types" ADD CONSTRAINT "deed_type_has_document_types_deed_type_uid_fkey" FOREIGN KEY ("deed_type_uid") REFERENCES "deed_types"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ model Contacts {
|
|||||||
last_name String @db.VarChar(255)
|
last_name String @db.VarChar(255)
|
||||||
email String @unique @db.VarChar(255)
|
email String @unique @db.VarChar(255)
|
||||||
phone_number String? @db.VarChar(50)
|
phone_number String? @db.VarChar(50)
|
||||||
cell_phone_number String? @unique @db.VarChar(50)
|
cell_phone_number String @unique @db.VarChar(50)
|
||||||
civility ECivility @default(MALE)
|
civility ECivility @default(MALE)
|
||||||
address Addresses? @relation(fields: [address_uid], references: [uid], onDelete: Cascade)
|
address Addresses? @relation(fields: [address_uid], references: [uid], onDelete: Cascade)
|
||||||
address_uid String @unique @db.VarChar(255)
|
address_uid String @unique @db.VarChar(255)
|
||||||
|
@ -55,6 +55,7 @@ import {
|
|||||||
|
|
||||||
const uidOfficeFolder1: string = randomString();
|
const uidOfficeFolder1: string = randomString();
|
||||||
const uidOfficeFolder2: string = randomString();
|
const uidOfficeFolder2: string = randomString();
|
||||||
|
<<<<<<< HEAD
|
||||||
const uidOfficeFolder3: string = randomString();
|
const uidOfficeFolder3: string = randomString();
|
||||||
const uidOfficeFolder4: string = randomString();
|
const uidOfficeFolder4: string = randomString();
|
||||||
const uidOfficeFolder5: string = randomString();
|
const uidOfficeFolder5: string = randomString();
|
||||||
@ -64,6 +65,11 @@ import {
|
|||||||
const uidDeed3: string = randomString();
|
const uidDeed3: string = randomString();
|
||||||
const uidDeed4: string = randomString();
|
const uidDeed4: string = randomString();
|
||||||
const uidDeed5: string = randomString();
|
const uidDeed5: string = randomString();
|
||||||
|
=======
|
||||||
|
|
||||||
|
const uidDeed1: string = randomString();
|
||||||
|
const uidDeed2: string = randomString();
|
||||||
|
>>>>>>> 7122ff1 (uuid --> uid)
|
||||||
|
|
||||||
const uidDeedType1: string = randomString();
|
const uidDeedType1: string = randomString();
|
||||||
const uidDeedType2: string = randomString();
|
const uidDeedType2: string = randomString();
|
||||||
@ -199,8 +205,13 @@ import {
|
|||||||
const officeFolders: OfficeFolders[] = [
|
const officeFolders: OfficeFolders[] = [
|
||||||
{
|
{
|
||||||
uid: uidOfficeFolder1,
|
uid: uidOfficeFolder1,
|
||||||
|
<<<<<<< HEAD
|
||||||
folder_number: "0001",
|
folder_number: "0001",
|
||||||
name: "Dossier",
|
name: "Dossier",
|
||||||
|
=======
|
||||||
|
folder_number: randomString(),
|
||||||
|
name: "0001",
|
||||||
|
>>>>>>> 7122ff1 (uuid --> uid)
|
||||||
deed_uid: uidDeed1,
|
deed_uid: uidDeed1,
|
||||||
status: EFolderStatus.LIVE,
|
status: EFolderStatus.LIVE,
|
||||||
created_at: new Date(),
|
created_at: new Date(),
|
||||||
@ -211,8 +222,13 @@ import {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
uid: uidOfficeFolder2,
|
uid: uidOfficeFolder2,
|
||||||
|
<<<<<<< HEAD
|
||||||
folder_number: "0002",
|
folder_number: "0002",
|
||||||
name: "Dossier",
|
name: "Dossier",
|
||||||
|
=======
|
||||||
|
folder_number: randomString(),
|
||||||
|
name: "0001",
|
||||||
|
>>>>>>> 7122ff1 (uuid --> uid)
|
||||||
deed_uid: uidDeed2,
|
deed_uid: uidDeed2,
|
||||||
status: EFolderStatus.LIVE,
|
status: EFolderStatus.LIVE,
|
||||||
created_at: new Date(),
|
created_at: new Date(),
|
||||||
@ -263,17 +279,24 @@ import {
|
|||||||
{
|
{
|
||||||
uid: uidDeed1,
|
uid: uidDeed1,
|
||||||
deed_type_uid: uidDeedType1,
|
deed_type_uid: uidDeedType1,
|
||||||
|
<<<<<<< HEAD
|
||||||
created_at: new Date(),
|
created_at: new Date(),
|
||||||
updated_at: new Date(),
|
updated_at: new Date(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
uid: uidDeed2,
|
uid: uidDeed2,
|
||||||
deed_type_uid: uidDeedType2,
|
deed_type_uid: uidDeedType2,
|
||||||
|
=======
|
||||||
|
>>>>>>> 7122ff1 (uuid --> uid)
|
||||||
created_at: new Date(),
|
created_at: new Date(),
|
||||||
updated_at: new Date(),
|
updated_at: new Date(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
<<<<<<< HEAD
|
||||||
uid: uidDeed3,
|
uid: uidDeed3,
|
||||||
|
=======
|
||||||
|
uid: uidDeed2,
|
||||||
|
>>>>>>> 7122ff1 (uuid --> uid)
|
||||||
deed_type_uid: uidDeedType2,
|
deed_type_uid: uidDeedType2,
|
||||||
created_at: new Date(),
|
created_at: new Date(),
|
||||||
updated_at: new Date(),
|
updated_at: new Date(),
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import Database from "@Common/databases/database";
|
import Database from "@Common/databases/database";
|
||||||
import BaseRepository from "@Repositories/BaseRepository";
|
import BaseRepository from "@Repositories/BaseRepository";
|
||||||
import { Service } from "typedi";
|
import { Service } from "typedi";
|
||||||
import { Customers, ECivility, ECustomerStatus, Prisma } from "@prisma/client";
|
import { Contacts, Customers, ECivility, ECustomerStatus, Prisma } from "@prisma/client";
|
||||||
import { Customer } from "le-coffre-resources/dist/SuperAdmin";
|
import { Customer } from "le-coffre-resources/dist/SuperAdmin";
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
@ -19,15 +19,24 @@ export default class CustomersRepository extends BaseRepository {
|
|||||||
/**
|
/**
|
||||||
* @description : Find many customers
|
* @description : Find many customers
|
||||||
*/
|
*/
|
||||||
public async findMany(query: any): Promise<Customers[]> {
|
public async findMany(query: Prisma.CustomersFindManyArgs): Promise<
|
||||||
|
(Customers & {
|
||||||
|
contact: Contacts;
|
||||||
|
})[]
|
||||||
|
> {
|
||||||
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
|
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
|
||||||
return this.model.findMany(query);
|
if (!query.include) return this.model.findMany({ ...query, include: { contact: true } });
|
||||||
|
return this.model.findMany({ ...query, include: { contact: { include: { address: true } } } });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description : Create a customer
|
* @description : Create a customer
|
||||||
*/
|
*/
|
||||||
public async create(customer: Customer): Promise<Customers> {
|
public async create(customer: Customer): Promise<
|
||||||
|
Customers & {
|
||||||
|
contact: Contacts;
|
||||||
|
}
|
||||||
|
> {
|
||||||
const createArgs: Prisma.CustomersCreateArgs = {
|
const createArgs: Prisma.CustomersCreateArgs = {
|
||||||
data: {
|
data: {
|
||||||
status: ECustomerStatus.PENDING,
|
status: ECustomerStatus.PENDING,
|
||||||
@ -39,7 +48,7 @@ export default class CustomersRepository extends BaseRepository {
|
|||||||
phone_number: customer.contact.phone_number,
|
phone_number: customer.contact.phone_number,
|
||||||
cell_phone_number: customer.contact?.cell_phone_number,
|
cell_phone_number: customer.contact?.cell_phone_number,
|
||||||
civility: ECivility[customer.contact.civility as keyof typeof ECivility],
|
civility: ECivility[customer.contact.civility as keyof typeof ECivility],
|
||||||
address: {}
|
address: {},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -52,13 +61,20 @@ export default class CustomersRepository extends BaseRepository {
|
|||||||
city: customer.contact.address!.city,
|
city: customer.contact.address!.city,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return this.model.create(createArgs);
|
return this.model.create({ ...createArgs, include: { contact: true } });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description : Update data from a customer
|
* @description : Update data from a customer
|
||||||
*/
|
*/
|
||||||
public async update(uid: string, customer: Customer): Promise<Customers> {
|
public async update(
|
||||||
|
uid: string,
|
||||||
|
customer: Customer,
|
||||||
|
): Promise<
|
||||||
|
Customers & {
|
||||||
|
contact: Contacts;
|
||||||
|
}
|
||||||
|
> {
|
||||||
const updateArgs: Prisma.CustomersUpdateArgs = {
|
const updateArgs: Prisma.CustomersUpdateArgs = {
|
||||||
where: {
|
where: {
|
||||||
uid: uid,
|
uid: uid,
|
||||||
@ -73,11 +89,11 @@ export default class CustomersRepository extends BaseRepository {
|
|||||||
phone_number: customer.contact.phone_number,
|
phone_number: customer.contact.phone_number,
|
||||||
cell_phone_number: customer.contact.cell_phone_number,
|
cell_phone_number: customer.contact.cell_phone_number,
|
||||||
civility: ECivility[customer.contact.civility as keyof typeof ECivility],
|
civility: ECivility[customer.contact.civility as keyof typeof ECivility],
|
||||||
address: {}
|
address: {},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
};
|
||||||
if (customer.contact.address) {
|
if (customer.contact.address) {
|
||||||
updateArgs.data.contact!.update!.address!.update = {
|
updateArgs.data.contact!.update!.address!.update = {
|
||||||
address: customer.contact.address!.address,
|
address: customer.contact.address!.address,
|
||||||
@ -85,7 +101,7 @@ export default class CustomersRepository extends BaseRepository {
|
|||||||
city: customer.contact.address!.city,
|
city: customer.contact.address!.city,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return this.model.update(updateArgs);
|
return this.model.update({ ...updateArgs, include: { contact: true } });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import Database from "@Common/databases/database";
|
import Database from "@Common/databases/database";
|
||||||
import BaseRepository from "@Repositories/BaseRepository";
|
import BaseRepository from "@Repositories/BaseRepository";
|
||||||
import { Service } from "typedi";
|
import { Service } from "typedi";
|
||||||
import { ECivility, Prisma, Users } from "@prisma/client";
|
import { Addresses, Contacts, ECivility, Offices, Prisma, Users } from "@prisma/client";
|
||||||
import User from "le-coffre-resources/dist/SuperAdmin";
|
import User from "le-coffre-resources/dist/SuperAdmin";
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
@ -19,15 +19,26 @@ export default class UsersRepository extends BaseRepository {
|
|||||||
/**
|
/**
|
||||||
* @description : Find many users
|
* @description : Find many users
|
||||||
*/
|
*/
|
||||||
public async findMany(query: any): Promise<Users[]> {
|
public async findMany(query: Prisma.UsersFindManyArgs): Promise<
|
||||||
|
(Users & {
|
||||||
|
contact: Contacts;
|
||||||
|
office_membership: Offices & {
|
||||||
|
address: Addresses
|
||||||
|
};
|
||||||
|
})[]
|
||||||
|
> {
|
||||||
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
|
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
|
||||||
return this.model.findMany(query);
|
if (!query.include) return this.model.findMany({ ...query, include: { contact: true, office_membership: { include: { address: true } } } });
|
||||||
|
return this.model.findMany({ ...query, include: { contact: { include: { address: true } }, office_membership: { include: { address: true } } } });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description : Create a user
|
* @description : Create a user
|
||||||
*/
|
*/
|
||||||
public async create(user: User): Promise<Users> {
|
public async create(user: User): Promise<Users & {
|
||||||
|
contact: Contacts;
|
||||||
|
office_membership: Offices;
|
||||||
|
}> {
|
||||||
const createArgs: Prisma.UsersCreateArgs = {
|
const createArgs: Prisma.UsersCreateArgs = {
|
||||||
data: {
|
data: {
|
||||||
idNot: user.idNot,
|
idNot: user.idNot,
|
||||||
@ -62,7 +73,7 @@ export default class UsersRepository extends BaseRepository {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
};
|
||||||
if (user.contact.address) {
|
if (user.contact.address) {
|
||||||
createArgs.data.contact!.create!.address!.create = {
|
createArgs.data.contact!.create!.address!.create = {
|
||||||
address: user.contact.address!.address,
|
address: user.contact.address!.address,
|
||||||
@ -70,13 +81,16 @@ export default class UsersRepository extends BaseRepository {
|
|||||||
city: user.contact.address!.city,
|
city: user.contact.address!.city,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return this.model.create(createArgs);
|
return this.model.create({...createArgs, include : { contact: true, office_membership: true}});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description : Update data from a user
|
* @description : Update data from a user
|
||||||
*/
|
*/
|
||||||
public async update(uid: string, user: User): Promise<Users> {
|
public async update(uid: string, user: User): Promise<Users & {
|
||||||
|
contact: Contacts;
|
||||||
|
office_membership: Offices;
|
||||||
|
}> {
|
||||||
const updateArgs: Prisma.UsersUpdateArgs = {
|
const updateArgs: Prisma.UsersUpdateArgs = {
|
||||||
where: {
|
where: {
|
||||||
uid: uid,
|
uid: uid,
|
||||||
@ -110,7 +124,7 @@ export default class UsersRepository extends BaseRepository {
|
|||||||
phone_number: user.contact.phone_number,
|
phone_number: user.contact.phone_number,
|
||||||
cell_phone_number: user.contact.cell_phone_number,
|
cell_phone_number: user.contact.cell_phone_number,
|
||||||
civility: ECivility[user.contact.civility as keyof typeof ECivility],
|
civility: ECivility[user.contact.civility as keyof typeof ECivility],
|
||||||
address: {}
|
address: {},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -122,7 +136,7 @@ export default class UsersRepository extends BaseRepository {
|
|||||||
city: user.contact.address!.city,
|
city: user.contact.address!.city,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return this.model.update(updateArgs);
|
return this.model.update({...updateArgs, include : { contact: true, office_membership: true}});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Customers } from "@prisma/client";
|
import { Contacts, Customers } from "@prisma/client";
|
||||||
import CustomersRepository from "@Repositories/CustomersRepository";
|
import CustomersRepository from "@Repositories/CustomersRepository";
|
||||||
import BaseService from "@Services/BaseService";
|
import BaseService from "@Services/BaseService";
|
||||||
import { Customer } from "le-coffre-resources/dist/SuperAdmin";
|
import { Customer } from "le-coffre-resources/dist/SuperAdmin";
|
||||||
@ -14,7 +14,11 @@ export default class CustomersService extends BaseService {
|
|||||||
* @description : Get all Customers
|
* @description : Get all Customers
|
||||||
* @throws {Error} If Customers cannot be get
|
* @throws {Error} If Customers cannot be get
|
||||||
*/
|
*/
|
||||||
public async get(query: any) {
|
public async get(query: any): Promise<
|
||||||
|
(Customers & {
|
||||||
|
contact: Contacts;
|
||||||
|
})[]
|
||||||
|
> {
|
||||||
return this.customerRepository.findMany(query);
|
return this.customerRepository.findMany(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,7 +26,11 @@ export default class CustomersService extends BaseService {
|
|||||||
* @description : Create a new customer
|
* @description : Create a new customer
|
||||||
* @throws {Error} If customer cannot be created
|
* @throws {Error} If customer cannot be created
|
||||||
*/
|
*/
|
||||||
public async create(customerEntity: Customer): Promise<Customers> {
|
public async create(customerEntity: Customer): Promise<
|
||||||
|
Customers & {
|
||||||
|
contact: Contacts;
|
||||||
|
}
|
||||||
|
> {
|
||||||
return this.customerRepository.create(customerEntity);
|
return this.customerRepository.create(customerEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,7 +38,14 @@ export default class CustomersService extends BaseService {
|
|||||||
* @description : Modify a customer
|
* @description : Modify a customer
|
||||||
* @throws {Error} If customer cannot be modified
|
* @throws {Error} If customer cannot be modified
|
||||||
*/
|
*/
|
||||||
public async update(uid: string, customerEntity: Customer): Promise<Customers> {
|
public async update(
|
||||||
|
uid: string,
|
||||||
|
customerEntity: Customer,
|
||||||
|
): Promise<
|
||||||
|
Customers & {
|
||||||
|
contact: Contacts;
|
||||||
|
}
|
||||||
|
> {
|
||||||
return this.customerRepository.update(uid, customerEntity);
|
return this.customerRepository.update(uid, customerEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ import "reflect-metadata";
|
|||||||
import { Service } from "typedi";
|
import { Service } from "typedi";
|
||||||
import UsersRepository from "@Repositories/UsersRepository";
|
import UsersRepository from "@Repositories/UsersRepository";
|
||||||
import User from "le-coffre-resources/dist/SuperAdmin";
|
import User from "le-coffre-resources/dist/SuperAdmin";
|
||||||
import { Users } from "@prisma/client";
|
import { Contacts, Offices, Prisma, Users } from "@prisma/client";
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class UsersService extends BaseService {
|
export default class UsersService extends BaseService {
|
||||||
@ -15,7 +15,10 @@ export default class UsersService extends BaseService {
|
|||||||
* @description : Get all users
|
* @description : Get all users
|
||||||
* @throws {Error} If users cannot be get
|
* @throws {Error} If users cannot be get
|
||||||
*/
|
*/
|
||||||
public get(query: any): Promise<Users[]> {
|
public get(query: Prisma.UsersFindManyArgs): Promise<(Users & {
|
||||||
|
contact: Contacts;
|
||||||
|
office_membership: Offices;
|
||||||
|
})[]> {
|
||||||
return this.userRepository.findMany(query);
|
return this.userRepository.findMany(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23,7 +26,10 @@ export default class UsersService extends BaseService {
|
|||||||
* @description : Create a user
|
* @description : Create a user
|
||||||
* @throws {Error} If user couldn't be created
|
* @throws {Error} If user couldn't be created
|
||||||
*/
|
*/
|
||||||
public create(userEntity: User): Promise<Users> {
|
public create(userEntity: User): Promise<Users & {
|
||||||
|
contact: Contacts;
|
||||||
|
office_membership: Offices;
|
||||||
|
}> {
|
||||||
return this.userRepository.create(userEntity);
|
return this.userRepository.create(userEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,7 +37,10 @@ export default class UsersService extends BaseService {
|
|||||||
* @description : Modify a user
|
* @description : Modify a user
|
||||||
* @throws {Error} If user modification failed
|
* @throws {Error} If user modification failed
|
||||||
*/
|
*/
|
||||||
public update(uid: string, userEntity: User): Promise<Users> {
|
public update(uid: string, userEntity: User): Promise<Users & {
|
||||||
|
contact: Contacts;
|
||||||
|
office_membership: Offices;
|
||||||
|
}> {
|
||||||
return this.userRepository.update(uid, userEntity);
|
return this.userRepository.update(uid, userEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user