🐛 Can now update excluded vars

This commit is contained in:
Maxime Lalo 2023-11-24 10:49:00 +01:00
parent ee97ccbf46
commit 65d6e548d1
2 changed files with 21 additions and 11 deletions

View File

@ -4,6 +4,13 @@ import { Service } from "typedi";
import { Customers, ECivility, ECustomerStatus, Prisma } from "@prisma/client"; import { Customers, ECivility, ECustomerStatus, Prisma } from "@prisma/client";
import { Customer } from "le-coffre-resources/dist/SuperAdmin"; import { Customer } from "le-coffre-resources/dist/SuperAdmin";
type IExcludedCustomerVars = {
smsCode?: string;
smsCodeExpire?: Date;
passwordCode?: string;
passwordcodeExpire?: Date;
password?: string;
};
@Service() @Service()
export default class CustomersRepository extends BaseRepository { export default class CustomersRepository extends BaseRepository {
constructor(private database: Database) { constructor(private database: Database) {
@ -70,7 +77,7 @@ export default class CustomersRepository extends BaseRepository {
/** /**
* @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, excludedVars?: IExcludedCustomerVars): Promise<Customers> {
const updateArgs: Prisma.CustomersUpdateArgs = { const updateArgs: Prisma.CustomersUpdateArgs = {
where: { where: {
uid: uid, uid: uid,
@ -88,13 +95,14 @@ export default class CustomersRepository extends BaseRepository {
address: {}, address: {},
}, },
}, },
smsCode: customer.smsCode, smsCode: excludedVars && excludedVars.smsCode,
smsCodeExpire: customer.smsCodeExpire, smsCodeExpire: excludedVars && excludedVars.smsCodeExpire,
passwordCode: customer.passwordCode, passwordCode: excludedVars && excludedVars.passwordCode,
passwordcodeExpire: customer.passwordCodeExpire, passwordcodeExpire: excludedVars && excludedVars.passwordcodeExpire,
password: customer.password, password: excludedVars && excludedVars.password,
}, },
}; };
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,

View File

@ -37,9 +37,11 @@ export default class CustomersService extends BaseService {
customer.uid as string, customer.uid as string,
Customer.hydrate<Customer>({ Customer.hydrate<Customer>({
...customer, ...customer,
smsCode: smsCode.toString(),
smsCodeExpire: new Date(now.getTime() + 5 * 60 * 1000),
}), }),
{
smsCode: smsCode.toString(),
smsCodeExpire: new Date(now.getTime() + 5 * 60000),
},
); );
} }
@ -52,10 +54,10 @@ export default class CustomersService extends BaseService {
customer.uid as string, customer.uid as string,
Customer.hydrate<Customer>({ Customer.hydrate<Customer>({
...customer, ...customer,
password,
smsCode: null,
smsCodeExpire: null,
}), }),
{
password,
},
); );
} }
} }