fixed bug
parent
6c2fd50ed0
commit
fde4f5ceea
|
@ -64,35 +64,48 @@ export async function UpdateStore(req: Request, res: Response) {
|
|||
// validate request
|
||||
|
||||
if (!storeId) {
|
||||
storeLogger.error("UpdateStore: invalid request", "no storeId provided");
|
||||
storeLogger.error(
|
||||
storeId,
|
||||
"UpdateStore: invalid request",
|
||||
"no storeId provided"
|
||||
);
|
||||
return res.status(400).send({ err: "invalid request" });
|
||||
}
|
||||
|
||||
const validations = [
|
||||
{
|
||||
value: name,
|
||||
validator: isCompanyNameValid,
|
||||
error: "invalid company name",
|
||||
},
|
||||
{
|
||||
value: phoneNumber,
|
||||
validator: isCompanyPhoneNumberValid,
|
||||
error: "invalid phone number",
|
||||
},
|
||||
{ value: email, validator: isEmailValid, error: "invalid email" },
|
||||
{
|
||||
value: address,
|
||||
validator: isCompanyAddressValid,
|
||||
error: "invalid address",
|
||||
},
|
||||
];
|
||||
if (!name && !phoneNumber && !email && !address) {
|
||||
storeLogger.error(
|
||||
storeId,
|
||||
"UpdateStore: invalid request",
|
||||
"no fields to update"
|
||||
);
|
||||
return res.status(400).send({ err: "invalid request" });
|
||||
}
|
||||
|
||||
for (let i = 0; i < validations.length; i++) {
|
||||
const { value, validator, error } = validations[i];
|
||||
if (value !== undefined && !validator(value)) {
|
||||
storeLogger.error("UpdateStore: invalid request", error);
|
||||
return res.status(400).send({ err: "invalid request" });
|
||||
}
|
||||
if (!isCompanyNameValid(name) || !isCompanyAddressValid(address)) {
|
||||
storeLogger.error(
|
||||
storeId,
|
||||
"UpdateStore: invalid request",
|
||||
"invalid name"
|
||||
);
|
||||
return res.status(400).send({ err: "invalid request" });
|
||||
}
|
||||
|
||||
if (phoneNumber && !isCompanyPhoneNumberValid(phoneNumber)) {
|
||||
storeLogger.error(
|
||||
storeId,
|
||||
"UpdateStore: invalid request",
|
||||
"invalid phone number"
|
||||
);
|
||||
return res.status(400).send({ err: "invalid request" });
|
||||
}
|
||||
|
||||
if (email && !(await isEmailValid(email, false))) {
|
||||
storeLogger.error(
|
||||
storeId,
|
||||
"UpdateStore: invalid request",
|
||||
"invalid email"
|
||||
);
|
||||
return res.status(400).send({ err: "invalid request" });
|
||||
}
|
||||
|
||||
// check if requester is the store owner
|
||||
|
|
|
@ -46,7 +46,7 @@ export async function isEmailValid(
|
|||
email: string,
|
||||
checkDatabase: boolean = true
|
||||
) {
|
||||
logger.info(`isEmailValid: ${email}`);
|
||||
logger.debug(`isEmailValid: ${email}`);
|
||||
|
||||
if (
|
||||
email.length < EMAIL_MIN_LENGTH ||
|
||||
|
|
Loading…
Reference in New Issue