|
|
|
@ -37,7 +37,10 @@ export default class drinkWaterUnit extends BaseApi { |
|
|
|
|
|
|
|
|
|
const result = await db.drinkWaterUnit.findAll({ |
|
|
|
|
where, |
|
|
|
|
order: [["rate", "ASC"]], |
|
|
|
|
order: [ |
|
|
|
|
["rate", "ASC"], |
|
|
|
|
["universityName", "ASC"], |
|
|
|
|
], |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
@ -69,21 +72,21 @@ export default class drinkWaterUnit extends BaseApi { |
|
|
|
|
add = async (data) => { |
|
|
|
|
const checkedData = _.pick(omitNull(data), db.drinkWaterUnit.add); |
|
|
|
|
|
|
|
|
|
const city = await db.city.findByPk(checkedData.cityId); |
|
|
|
|
if (!city) |
|
|
|
|
checkedData.rate = checkedData.rate.upperCase(); |
|
|
|
|
|
|
|
|
|
if (!["A", "B", "C", "D"].includes(checkedData.rate)) |
|
|
|
|
return { |
|
|
|
|
statusCode: 404, |
|
|
|
|
message: "شناسه شهر نامعتبر است", |
|
|
|
|
statusCode: 400, |
|
|
|
|
message: "بروز خطا در اطلاعات ورودی", |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const university = await db.university.findByPk(checkedData.universityId); |
|
|
|
|
if (!university) |
|
|
|
|
const result = await db.drinkWaterUnit.create(checkedData); |
|
|
|
|
if (!result) |
|
|
|
|
return { |
|
|
|
|
statusCode: 404, |
|
|
|
|
message: "شناسه دانشگاه نامعتبر است", |
|
|
|
|
statusCode: 400, |
|
|
|
|
message: "درخواست انجام نشد.", |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const result = await db.drinkWaterUnit.create(checkedData); |
|
|
|
|
return { id: result.dataValues.id }; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
@ -104,6 +107,15 @@ export default class drinkWaterUnit extends BaseApi { |
|
|
|
|
message: "بروز خطا در اطلاعات ورودی", |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
if (checkedData.rate) { |
|
|
|
|
checkedData.rate = checkedData.rate.upperCase(); |
|
|
|
|
if (!["A", "B", "C", "D"].includes(checkedData.rate)) |
|
|
|
|
return { |
|
|
|
|
statusCode: 400, |
|
|
|
|
message: "درخواست انجام نشد.", |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const { id } = data; |
|
|
|
|
|
|
|
|
|
const result = await db.drinkWaterUnit.update(checkedData, { |
|
|
|
|