🐛 Can now update excluded vars
This commit is contained in:
parent
ee97ccbf46
commit
65d6e548d1
@ -4,6 +4,13 @@ import { Service } from "typedi";
|
||||
import { Customers, ECivility, ECustomerStatus, Prisma } from "@prisma/client";
|
||||
import { Customer } from "le-coffre-resources/dist/SuperAdmin";
|
||||
|
||||
type IExcludedCustomerVars = {
|
||||
smsCode?: string;
|
||||
smsCodeExpire?: Date;
|
||||
passwordCode?: string;
|
||||
passwordcodeExpire?: Date;
|
||||
password?: string;
|
||||
};
|
||||
@Service()
|
||||
export default class CustomersRepository extends BaseRepository {
|
||||
constructor(private database: Database) {
|
||||
@ -70,7 +77,7 @@ export default class CustomersRepository extends BaseRepository {
|
||||
/**
|
||||
* @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 = {
|
||||
where: {
|
||||
uid: uid,
|
||||
@ -88,13 +95,14 @@ export default class CustomersRepository extends BaseRepository {
|
||||
address: {},
|
||||
},
|
||||
},
|
||||
smsCode: customer.smsCode,
|
||||
smsCodeExpire: customer.smsCodeExpire,
|
||||
passwordCode: customer.passwordCode,
|
||||
passwordcodeExpire: customer.passwordCodeExpire,
|
||||
password: customer.password,
|
||||
smsCode: excludedVars && excludedVars.smsCode,
|
||||
smsCodeExpire: excludedVars && excludedVars.smsCodeExpire,
|
||||
passwordCode: excludedVars && excludedVars.passwordCode,
|
||||
passwordcodeExpire: excludedVars && excludedVars.passwordcodeExpire,
|
||||
password: excludedVars && excludedVars.password,
|
||||
},
|
||||
};
|
||||
|
||||
if (customer.contact!.address) {
|
||||
updateArgs.data.contact!.update!.address!.update = {
|
||||
address: customer.contact!.address!.address,
|
||||
|
@ -37,9 +37,11 @@ export default class CustomersService extends BaseService {
|
||||
customer.uid as string,
|
||||
Customer.hydrate<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.hydrate<Customer>({
|
||||
...customer,
|
||||
password,
|
||||
smsCode: null,
|
||||
smsCodeExpire: null,
|
||||
}),
|
||||
{
|
||||
password,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user