refacto hydratation on post requests (#30)
This commit is contained in:
commit
0596b0947f
@ -46,8 +46,7 @@ export default class DocumentsController extends ApiController {
|
|||||||
protected async post(req: Request, response: Response) {
|
protected async post(req: Request, response: Response) {
|
||||||
try {
|
try {
|
||||||
//init Document resource with request body values
|
//init Document resource with request body values
|
||||||
const documentEntity = new Document();
|
const documentEntity = Document.hydrate<Document>(req.body);
|
||||||
Document.hydrate(documentEntity, req.body);
|
|
||||||
|
|
||||||
//validate document
|
//validate document
|
||||||
await validateOrReject(documentEntity, { groups: ["createDocument"] });
|
await validateOrReject(documentEntity, { groups: ["createDocument"] });
|
||||||
|
@ -44,15 +44,12 @@ export default class CustomersController extends ApiController {
|
|||||||
protected async post(req: Request, response: Response) {
|
protected async post(req: Request, response: Response) {
|
||||||
try {
|
try {
|
||||||
//init IUser resource with request body values
|
//init IUser resource with request body values
|
||||||
const customerEntity = new Customer();
|
const customerEntity = Customer.hydrate<Customer>(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 });
|
||||||
|
|
||||||
//call service to get prisma entity
|
//call service to get prisma entity
|
||||||
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 = Customer.hydrate<Customer>(prismaEntityCreated, {
|
const customerEntityCreated = Customer.hydrate<Customer>(prismaEntityCreated, {
|
||||||
strategy: "excludeAll",
|
strategy: "excludeAll",
|
||||||
|
@ -4,7 +4,6 @@ import ApiController from "@Common/system/controller-pattern/ApiController";
|
|||||||
import { Service } from "typedi";
|
import { Service } from "typedi";
|
||||||
import DeedTypesService from "@Services/super-admin/DeedTypesService/DeedTypesService";
|
import DeedTypesService from "@Services/super-admin/DeedTypesService/DeedTypesService";
|
||||||
import { DeedTypes } from "@prisma/client";
|
import { DeedTypes } from "@prisma/client";
|
||||||
import ObjectHydrate from "@Common/helpers/ObjectHydrate";
|
|
||||||
import { DeedType } from "le-coffre-resources/dist/SuperAdmin";
|
import { DeedType } from "le-coffre-resources/dist/SuperAdmin";
|
||||||
import { validateOrReject } from "class-validator";
|
import { validateOrReject } from "class-validator";
|
||||||
|
|
||||||
@ -46,8 +45,7 @@ export default class DeedTypesController extends ApiController {
|
|||||||
protected async post(req: Request, response: Response) {
|
protected async post(req: Request, response: Response) {
|
||||||
try {
|
try {
|
||||||
//init DeedType resource with request body values
|
//init DeedType resource with request body values
|
||||||
const deedTypeEntity = new DeedType();
|
const deedTypeEntity = DeedType.hydrate<DeedType>(req.body);
|
||||||
ObjectHydrate.hydrate(deedTypeEntity, req.body);
|
|
||||||
|
|
||||||
//validate deed type
|
//validate deed type
|
||||||
await validateOrReject(deedTypeEntity, { groups: ["createDeedType"], forbidUnknownValues: false });
|
await validateOrReject(deedTypeEntity, { groups: ["createDeedType"], forbidUnknownValues: false });
|
||||||
@ -80,8 +78,7 @@ export default class DeedTypesController extends ApiController {
|
|||||||
throw new Error("No uid provided");
|
throw new Error("No uid provided");
|
||||||
}
|
}
|
||||||
//init DeedType resource with request body values
|
//init DeedType resource with request body values
|
||||||
const deedTypeEntity = new DeedType();
|
const deedTypeEntity = DeedType.hydrate<DeedType>(req.body);
|
||||||
ObjectHydrate.hydrate(deedTypeEntity, req.body);
|
|
||||||
|
|
||||||
//validate deed type
|
//validate deed type
|
||||||
await validateOrReject(deedTypeEntity, { groups: ["updateDeedType"] });
|
await validateOrReject(deedTypeEntity, { groups: ["updateDeedType"] });
|
||||||
|
@ -7,7 +7,6 @@ import { DocumentTypes } from "@prisma/client";
|
|||||||
import ObjectHydrate from "@Common/helpers/ObjectHydrate";
|
import ObjectHydrate from "@Common/helpers/ObjectHydrate";
|
||||||
import { DocumentType } from "le-coffre-resources/dist/SuperAdmin";
|
import { DocumentType } from "le-coffre-resources/dist/SuperAdmin";
|
||||||
import { validateOrReject } from "class-validator";
|
import { validateOrReject } from "class-validator";
|
||||||
//import { validateOrReject } from "class-validator";
|
|
||||||
|
|
||||||
@Controller()
|
@Controller()
|
||||||
@Service()
|
@Service()
|
||||||
@ -48,8 +47,7 @@ export default class DocumentTypesController extends ApiController {
|
|||||||
protected async post(req: Request, response: Response) {
|
protected async post(req: Request, response: Response) {
|
||||||
try {
|
try {
|
||||||
//init DocumentType resource with request body values
|
//init DocumentType resource with request body values
|
||||||
const documentTypeEntity = new DocumentType();
|
const documentTypeEntity = DocumentType.hydrate<DocumentType>(req.body);
|
||||||
ObjectHydrate.hydrate(documentTypeEntity, req.body);
|
|
||||||
//validate user
|
//validate user
|
||||||
await validateOrReject(documentTypeEntity, { groups: ["createDocumentType"], forbidUnknownValues: false });
|
await validateOrReject(documentTypeEntity, { groups: ["createDocumentType"], forbidUnknownValues: false });
|
||||||
//call service to get prisma entity
|
//call service to get prisma entity
|
||||||
@ -77,8 +75,7 @@ export default class DocumentTypesController extends ApiController {
|
|||||||
throw new Error("No uid provided");
|
throw new Error("No uid provided");
|
||||||
}
|
}
|
||||||
//init DocumentType resource with request body values
|
//init DocumentType resource with request body values
|
||||||
const documentTypeEntity = new DocumentType();
|
const documentTypeEntity = DocumentType.hydrate<DocumentType>(req.body);
|
||||||
ObjectHydrate.hydrate(documentTypeEntity, req.body);
|
|
||||||
|
|
||||||
//validate user
|
//validate user
|
||||||
await validateOrReject(documentTypeEntity, { groups: ["update"] });
|
await validateOrReject(documentTypeEntity, { groups: ["update"] });
|
||||||
|
@ -4,7 +4,6 @@ import ApiController from "@Common/system/controller-pattern/ApiController";
|
|||||||
import { Service } from "typedi";
|
import { Service } from "typedi";
|
||||||
import DocumentsService from "@Services/super-admin/DocumentsService/DocumentsService";
|
import DocumentsService from "@Services/super-admin/DocumentsService/DocumentsService";
|
||||||
import { Documents } from "@prisma/client";
|
import { Documents } from "@prisma/client";
|
||||||
import ObjectHydrate from "@Common/helpers/ObjectHydrate";
|
|
||||||
import { Document } from "le-coffre-resources/dist/SuperAdmin";
|
import { Document } from "le-coffre-resources/dist/SuperAdmin";
|
||||||
import { validateOrReject } from "class-validator";
|
import { validateOrReject } from "class-validator";
|
||||||
|
|
||||||
@ -47,8 +46,7 @@ export default class DocumentsController extends ApiController {
|
|||||||
protected async post(req: Request, response: Response) {
|
protected async post(req: Request, response: Response) {
|
||||||
try {
|
try {
|
||||||
//init Document resource with request body values
|
//init Document resource with request body values
|
||||||
const documentEntity = new Document();
|
const documentEntity = Document.hydrate<Document>(req.body);
|
||||||
ObjectHydrate.hydrate(documentEntity, req.body);
|
|
||||||
|
|
||||||
//validate document
|
//validate document
|
||||||
await validateOrReject(documentEntity, { groups: ["createDocument"], forbidUnknownValues: false });
|
await validateOrReject(documentEntity, { groups: ["createDocument"], forbidUnknownValues: false });
|
||||||
@ -81,8 +79,7 @@ export default class DocumentsController extends ApiController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//init Document resource with request body values
|
//init Document resource with request body values
|
||||||
const documentEntity = new Document();
|
const documentEntity = Document.hydrate<Document>(req.body);
|
||||||
ObjectHydrate.hydrate(documentEntity, req.body);
|
|
||||||
|
|
||||||
//validate document
|
//validate document
|
||||||
await validateOrReject(documentEntity, { groups: ["createDocument"] });
|
await validateOrReject(documentEntity, { groups: ["createDocument"] });
|
||||||
|
@ -4,7 +4,6 @@ import ApiController from "@Common/system/controller-pattern/ApiController";
|
|||||||
import OfficeFoldersService from "@Services/super-admin/OfficeFoldersService/OfficeFoldersService";
|
import OfficeFoldersService from "@Services/super-admin/OfficeFoldersService/OfficeFoldersService";
|
||||||
import { Service } from "typedi";
|
import { Service } from "typedi";
|
||||||
import { OfficeFolders } from "@prisma/client";
|
import { OfficeFolders } from "@prisma/client";
|
||||||
import ObjectHydrate from "@Common/helpers/ObjectHydrate";
|
|
||||||
import { OfficeFolder } from "le-coffre-resources/dist/SuperAdmin";
|
import { OfficeFolder } from "le-coffre-resources/dist/SuperAdmin";
|
||||||
import { validateOrReject } from "class-validator";
|
import { validateOrReject } from "class-validator";
|
||||||
|
|
||||||
@ -44,8 +43,7 @@ export default class OfficeFoldersController extends ApiController {
|
|||||||
protected async post(req: Request, response: Response) {
|
protected async post(req: Request, response: Response) {
|
||||||
try {
|
try {
|
||||||
//init OfficeFolder resource with request body values
|
//init OfficeFolder resource with request body values
|
||||||
const officeFolderEntity = new OfficeFolder();
|
const officeFolderEntity = OfficeFolder.hydrate<OfficeFolder>(req.body);
|
||||||
ObjectHydrate.hydrate(officeFolderEntity, req.body);
|
|
||||||
|
|
||||||
//validate folder
|
//validate folder
|
||||||
await validateOrReject(officeFolderEntity, { groups: ["create"] });
|
await validateOrReject(officeFolderEntity, { groups: ["create"] });
|
||||||
@ -73,11 +71,10 @@ export default class OfficeFoldersController extends ApiController {
|
|||||||
if (!uid) {
|
if (!uid) {
|
||||||
throw new Error("No uid provided");
|
throw new Error("No uid provided");
|
||||||
}
|
}
|
||||||
//init IUser resource with request body values
|
//init OfficeFolder resource with request body values
|
||||||
const officeFolderEntity = new OfficeFolder();
|
const officeFolderEntity = OfficeFolder.hydrate<OfficeFolder>(req.body);
|
||||||
ObjectHydrate.hydrate(officeFolderEntity, req.body);
|
|
||||||
|
|
||||||
//validate user
|
//validate folder
|
||||||
await validateOrReject(officeFolderEntity, { groups: ["updateFolder"], forbidUnknownValues: false });
|
await validateOrReject(officeFolderEntity, { groups: ["updateFolder"], forbidUnknownValues: false });
|
||||||
|
|
||||||
//call service to get prisma entity
|
//call service to get prisma entity
|
||||||
|
@ -4,7 +4,6 @@ import ApiController from "@Common/system/controller-pattern/ApiController";
|
|||||||
import OfficesService from "@Services/super-admin/OfficesService/OfficesService";
|
import OfficesService from "@Services/super-admin/OfficesService/OfficesService";
|
||||||
import { Service } from "typedi";
|
import { Service } from "typedi";
|
||||||
import { Offices } from "@prisma/client";
|
import { Offices } from "@prisma/client";
|
||||||
import ObjectHydrate from "@Common/helpers/ObjectHydrate";
|
|
||||||
import { Office as OfficeResource } from "le-coffre-resources/dist/SuperAdmin";
|
import { Office as OfficeResource } from "le-coffre-resources/dist/SuperAdmin";
|
||||||
import { validateOrReject } from "class-validator";
|
import { validateOrReject } from "class-validator";
|
||||||
|
|
||||||
@ -40,8 +39,7 @@ export default class OfficesController extends ApiController {
|
|||||||
protected async post(req: Request, response: Response) {
|
protected async post(req: Request, response: Response) {
|
||||||
try {
|
try {
|
||||||
//init IUser resource with request body values
|
//init IUser resource with request body values
|
||||||
const officeEntity = new OfficeResource();
|
const officeEntity = OfficeResource.hydrate<OfficeResource>(req.body);
|
||||||
ObjectHydrate.hydrate(officeEntity, req.body);
|
|
||||||
//validate user
|
//validate user
|
||||||
await validateOrReject(officeEntity, { groups: ["createOffice"], forbidUnknownValues: false });
|
await validateOrReject(officeEntity, { groups: ["createOffice"], forbidUnknownValues: false });
|
||||||
//call service to get prisma entity
|
//call service to get prisma entity
|
||||||
@ -68,8 +66,7 @@ export default class OfficesController extends ApiController {
|
|||||||
throw new Error("No uid provided");
|
throw new Error("No uid provided");
|
||||||
}
|
}
|
||||||
//init IUser resource with request body values
|
//init IUser resource with request body values
|
||||||
const officeEntity = new OfficeResource();
|
const officeEntity = OfficeResource.hydrate<OfficeResource>(req.body);
|
||||||
ObjectHydrate.hydrate(officeEntity, req.body);
|
|
||||||
//validate user
|
//validate user
|
||||||
await validateOrReject(officeEntity, { groups: ["update"] });
|
await validateOrReject(officeEntity, { groups: ["update"] });
|
||||||
//call service to get prisma entity
|
//call service to get prisma entity
|
||||||
|
@ -3,7 +3,6 @@ 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 UsersService from "@Services/super-admin/UsersService/UsersService";
|
import UsersService from "@Services/super-admin/UsersService/UsersService";
|
||||||
import { Service } from "typedi";
|
import { Service } from "typedi";
|
||||||
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";
|
||||||
@ -45,8 +44,7 @@ export default class UsersController extends ApiController {
|
|||||||
protected async getAddresses(req: Request, response: Response) {
|
protected async getAddresses(req: Request, response: Response) {
|
||||||
try {
|
try {
|
||||||
//init IUser resource with request body values
|
//init IUser resource with request body values
|
||||||
const userEntity = new User();
|
const userEntity = User.hydrate<User>(req.body);
|
||||||
ObjectHydrate.hydrate(userEntity, req.body);
|
|
||||||
|
|
||||||
//validate user
|
//validate user
|
||||||
await validateOrReject(userEntity, { groups: ["createUser"] });
|
await validateOrReject(userEntity, { groups: ["createUser"] });
|
||||||
@ -78,8 +76,7 @@ export default class UsersController extends ApiController {
|
|||||||
throw new Error("No uid provided");
|
throw new Error("No uid provided");
|
||||||
}
|
}
|
||||||
//init IUser resource with request body values
|
//init IUser resource with request body values
|
||||||
const userEntity = new User();
|
const userEntity = User.hydrate<User>(req.body);
|
||||||
ObjectHydrate.hydrate(userEntity, req.body);
|
|
||||||
|
|
||||||
//validate user
|
//validate user
|
||||||
await validateOrReject(userEntity, { groups: ["update"] });
|
await validateOrReject(userEntity, { groups: ["update"] });
|
||||||
|
@ -444,3 +444,6 @@ 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;
|
||||||
|
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "contacts" ALTER COLUMN "cell_phone_number" SET NOT NULL,
|
||||||
|
ALTER COLUMN "address_uid" DROP NOT NULL;
|
@ -39,7 +39,7 @@ model Contacts {
|
|||||||
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)
|
||||||
birthdate DateTime?
|
birthdate DateTime?
|
||||||
created_at DateTime? @default(now())
|
created_at DateTime? @default(now())
|
||||||
updated_at DateTime? @updatedAt
|
updated_at DateTime? @updatedAt
|
||||||
|
@ -32,11 +32,7 @@ export default class CustomersRepository extends BaseRepository {
|
|||||||
/**
|
/**
|
||||||
* @description : Create a customer
|
* @description : Create a customer
|
||||||
*/
|
*/
|
||||||
public async create(customer: Customer): Promise<
|
public async create(customer: Customer): Promise<Customers> {
|
||||||
Customers & {
|
|
||||||
contact: Contacts;
|
|
||||||
}
|
|
||||||
> {
|
|
||||||
const createArgs: Prisma.CustomersCreateArgs = {
|
const createArgs: Prisma.CustomersCreateArgs = {
|
||||||
data: {
|
data: {
|
||||||
status: ECustomerStatus.PENDING,
|
status: ECustomerStatus.PENDING,
|
||||||
@ -46,7 +42,7 @@ export default class CustomersRepository extends BaseRepository {
|
|||||||
last_name: customer.contact!.last_name,
|
last_name: customer.contact!.last_name,
|
||||||
email: customer.contact!.email,
|
email: customer.contact!.email,
|
||||||
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: {},
|
||||||
},
|
},
|
||||||
@ -55,10 +51,12 @@ export default class CustomersRepository extends BaseRepository {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (customer.contact!.address) {
|
if (customer.contact!.address) {
|
||||||
createArgs.data.contact!.create!.address!.create = {
|
createArgs.data.contact!.create!.address = {
|
||||||
address: customer.contact!.address!.address,
|
create: {
|
||||||
zip_code: customer.contact!.address!.zip_code,
|
address: customer.contact!.address!.address,
|
||||||
city: customer.contact!.address!.city,
|
zip_code: customer.contact!.address!.zip_code,
|
||||||
|
city: customer.contact!.address!.city,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return this.model.create({ ...createArgs, include: { contact: true } });
|
return this.model.create({ ...createArgs, include: { contact: true } });
|
||||||
@ -67,14 +65,7 @@ export default class CustomersRepository extends BaseRepository {
|
|||||||
/**
|
/**
|
||||||
* @description : Update data from a customer
|
* @description : Update data from a customer
|
||||||
*/
|
*/
|
||||||
public async update(
|
public async update(uid: string, customer: Customer): Promise<Customers> {
|
||||||
uid: string,
|
|
||||||
customer: Customer,
|
|
||||||
): Promise<
|
|
||||||
Customers & {
|
|
||||||
contact: Contacts;
|
|
||||||
}
|
|
||||||
> {
|
|
||||||
const updateArgs: Prisma.CustomersUpdateArgs = {
|
const updateArgs: Prisma.CustomersUpdateArgs = {
|
||||||
where: {
|
where: {
|
||||||
uid: uid,
|
uid: uid,
|
||||||
@ -107,21 +98,16 @@ export default class CustomersRepository extends BaseRepository {
|
|||||||
/**
|
/**
|
||||||
* @description : Find unique customer
|
* @description : Find unique customer
|
||||||
*/
|
*/
|
||||||
public async findOneByUid(
|
public async findOneByUid(uid: string, query?: any): Promise<Customers> {
|
||||||
uid: string,
|
|
||||||
query?: any,
|
|
||||||
): Promise<
|
|
||||||
Customers & {
|
|
||||||
contact: Contacts;
|
|
||||||
}
|
|
||||||
> {
|
|
||||||
const findOneArgs: Prisma.CustomersFindUniqueArgs = {
|
const findOneArgs: Prisma.CustomersFindUniqueArgs = {
|
||||||
where: {
|
where: {
|
||||||
uid: uid,
|
uid: uid,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const customerEntity = await this.model.findUnique({ ...findOneArgs, include: { contact: true } });
|
if (query) {
|
||||||
|
findOneArgs.include = query;
|
||||||
|
}
|
||||||
|
const customerEntity = await this.model.findUnique(findOneArgs);
|
||||||
if (!customerEntity) {
|
if (!customerEntity) {
|
||||||
throw new Error("Customer not found");
|
throw new Error("Customer not found");
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ describe("test create function", () => {
|
|||||||
expect(contactCreated?.email).toEqual(customer.contact!.email);
|
expect(contactCreated?.email).toEqual(customer.contact!.email);
|
||||||
|
|
||||||
// verify if customer address is created in db
|
// verify if customer address is created in db
|
||||||
const addressForContactCreated = await prisma.addresses.findUnique({ where: { uid: contactCreated?.address_uid } });
|
const addressForContactCreated = await prisma.addresses.findUnique({ where: { uid: contactCreated?.address_uid! } });
|
||||||
expect(addressForContactCreated?.address).toEqual(customer.contact!.address?.address);
|
expect(addressForContactCreated?.address).toEqual(customer.contact!.address?.address);
|
||||||
expect(addressForContactCreated?.zip_code).toEqual(customer.contact!.address?.zip_code);
|
expect(addressForContactCreated?.zip_code).toEqual(customer.contact!.address?.zip_code);
|
||||||
expect(addressForContactCreated?.city).toEqual(customer.contact!.address?.city);
|
expect(addressForContactCreated?.city).toEqual(customer.contact!.address?.city);
|
||||||
@ -92,7 +92,7 @@ describe("test create function", () => {
|
|||||||
expect(contactCreated?.email).toEqual(customer_.contact!.email);
|
expect(contactCreated?.email).toEqual(customer_.contact!.email);
|
||||||
|
|
||||||
// verify if customer_ address is created in db
|
// verify if customer_ address is created in db
|
||||||
const addressForContactCreated = await prisma.addresses.findUnique({ where: { uid: contactCreated?.address_uid } });
|
const addressForContactCreated = await prisma.addresses.findUnique({ where: { uid: contactCreated?.address_uid! } });
|
||||||
expect(addressForContactCreated?.address).toEqual(customer.contact!.address?.address);
|
expect(addressForContactCreated?.address).toEqual(customer.contact!.address?.address);
|
||||||
expect(addressForContactCreated?.zip_code).toEqual(customer.contact!.address?.zip_code);
|
expect(addressForContactCreated?.zip_code).toEqual(customer.contact!.address?.zip_code);
|
||||||
expect(addressForContactCreated?.city).toEqual(customer.contact!.address?.city);
|
expect(addressForContactCreated?.city).toEqual(customer.contact!.address?.city);
|
||||||
@ -118,7 +118,7 @@ describe("test update function", () => {
|
|||||||
expect(existingContact?.email).toEqual(customer_.contact!.email);
|
expect(existingContact?.email).toEqual(customer_.contact!.email);
|
||||||
|
|
||||||
// verify if customer_ address is created in db
|
// verify if customer_ address is created in db
|
||||||
const addressForExistingContact = await prisma.addresses.findUnique({ where: { uid: existingContact?.address_uid } });
|
const addressForExistingContact = await prisma.addresses.findUnique({ where: { uid: existingContact?.address_uid! } });
|
||||||
expect(addressForExistingContact?.address).toEqual(customer_.contact!.address?.address);
|
expect(addressForExistingContact?.address).toEqual(customer_.contact!.address?.address);
|
||||||
expect(addressForExistingContact?.zip_code).toEqual(customer_.contact!.address?.zip_code);
|
expect(addressForExistingContact?.zip_code).toEqual(customer_.contact!.address?.zip_code);
|
||||||
expect(addressForExistingContact?.city).toEqual(customer_.contact!.address?.city);
|
expect(addressForExistingContact?.city).toEqual(customer_.contact!.address?.city);
|
||||||
|
@ -37,7 +37,7 @@ describe("test create function", () => {
|
|||||||
expect(contactCreated?.email).toEqual(user.contact!.email);
|
expect(contactCreated?.email).toEqual(user.contact!.email);
|
||||||
|
|
||||||
// verify if user address is created in db
|
// verify if user address is created in db
|
||||||
const addressForContactCreated = await prisma.addresses.findUnique({ where: { uid: contactCreated?.address_uid } });
|
const addressForContactCreated = await prisma.addresses.findUnique({ where: { uid: contactCreated?.address_uid! } });
|
||||||
expect(addressForContactCreated?.address).toEqual(user.contact!.address?.address);
|
expect(addressForContactCreated?.address).toEqual(user.contact!.address?.address);
|
||||||
expect(addressForContactCreated?.zip_code).toEqual(user.contact!.address?.zip_code);
|
expect(addressForContactCreated?.zip_code).toEqual(user.contact!.address?.zip_code);
|
||||||
expect(addressForContactCreated?.city).toEqual(user.contact!.address?.city);
|
expect(addressForContactCreated?.city).toEqual(user.contact!.address?.city);
|
||||||
@ -50,7 +50,7 @@ describe("test create function", () => {
|
|||||||
expect(officeCreated?.office_status).toEqual("DESACTIVATED");
|
expect(officeCreated?.office_status).toEqual("DESACTIVATED");
|
||||||
|
|
||||||
// verify if user office's address is created in db
|
// verify if user office's address is created in db
|
||||||
const addressForOfficeCreated = await prisma.addresses.findUnique({ where: { uid: officeCreated?.address_uid } });
|
const addressForOfficeCreated = await prisma.addresses.findUnique({ where: { uid: officeCreated?.address_uid! } });
|
||||||
expect(addressForOfficeCreated?.address).toEqual(user.office_membership!.address!.address);
|
expect(addressForOfficeCreated?.address).toEqual(user.office_membership!.address!.address);
|
||||||
expect(addressForOfficeCreated?.zip_code).toEqual(user.office_membership!.address!.zip_code);
|
expect(addressForOfficeCreated?.zip_code).toEqual(user.office_membership!.address!.zip_code);
|
||||||
expect(addressForOfficeCreated?.city).toEqual(user.office_membership!.address!.city);
|
expect(addressForOfficeCreated?.city).toEqual(user.office_membership!.address!.city);
|
||||||
@ -106,7 +106,7 @@ describe("test create function", () => {
|
|||||||
expect(contactCreated?.email).toEqual(user_.contact!.email);
|
expect(contactCreated?.email).toEqual(user_.contact!.email);
|
||||||
|
|
||||||
// verify if user_ address is created in db
|
// verify if user_ address is created in db
|
||||||
const addressForContactCreated = await prisma.addresses.findUnique({ where: { uid: contactCreated?.address_uid } });
|
const addressForContactCreated = await prisma.addresses.findUnique({ where: { uid: contactCreated?.address_uid! } });
|
||||||
expect(addressForContactCreated?.address).toEqual(user.contact!.address?.address);
|
expect(addressForContactCreated?.address).toEqual(user.contact!.address?.address);
|
||||||
expect(addressForContactCreated?.zip_code).toEqual(user.contact!.address?.zip_code);
|
expect(addressForContactCreated?.zip_code).toEqual(user.contact!.address?.zip_code);
|
||||||
expect(addressForContactCreated?.city).toEqual(user.contact!.address?.city);
|
expect(addressForContactCreated?.city).toEqual(user.contact!.address?.city);
|
||||||
@ -145,7 +145,7 @@ describe("test update function", () => {
|
|||||||
expect(existingContact?.email).toEqual(user_.contact!.email);
|
expect(existingContact?.email).toEqual(user_.contact!.email);
|
||||||
|
|
||||||
// verify if user_ address is created in db
|
// verify if user_ address is created in db
|
||||||
const addressForExistingContact = await prisma.addresses.findUnique({ where: { uid: existingContact?.address_uid } });
|
const addressForExistingContact = await prisma.addresses.findUnique({ where: { uid: existingContact?.address_uid! } });
|
||||||
expect(addressForExistingContact?.address).toEqual(user_.contact!.address?.address);
|
expect(addressForExistingContact?.address).toEqual(user_.contact!.address?.address);
|
||||||
expect(addressForExistingContact?.zip_code).toEqual(user_.contact!.address?.zip_code);
|
expect(addressForExistingContact?.zip_code).toEqual(user_.contact!.address?.zip_code);
|
||||||
expect(addressForExistingContact?.city).toEqual(user_.contact!.address?.city);
|
expect(addressForExistingContact?.city).toEqual(user_.contact!.address?.city);
|
||||||
@ -158,7 +158,7 @@ describe("test update function", () => {
|
|||||||
expect(officeCreated?.office_status).toEqual("DESACTIVATED");
|
expect(officeCreated?.office_status).toEqual("DESACTIVATED");
|
||||||
|
|
||||||
// verify is user_ office's address is created in db
|
// verify is user_ office's address is created in db
|
||||||
const addressForOfficeCreated = await prisma.addresses.findUnique({ where: { uid: officeCreated?.address_uid } });
|
const addressForOfficeCreated = await prisma.addresses.findUnique({ where: { uid: officeCreated?.address_uid! } });
|
||||||
expect(addressForOfficeCreated?.address).toEqual(user_.office_membership!.address!.address);
|
expect(addressForOfficeCreated?.address).toEqual(user_.office_membership!.address!.address);
|
||||||
expect(addressForOfficeCreated?.zip_code).toEqual(user_.office_membership!.address!.zip_code);
|
expect(addressForOfficeCreated?.zip_code).toEqual(user_.office_membership!.address!.zip_code);
|
||||||
expect(addressForOfficeCreated?.city).toEqual(user_.office_membership!.address!.city);
|
expect(addressForOfficeCreated?.city).toEqual(user_.office_membership!.address!.city);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user