master
mobinkazemi 3 years ago
parent 5e747aedaa
commit 877e845738
  1. 32
      drinkWaterUnitAPI.js
  2. 5
      drinkWaterUnitModel.js

@ -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, {

@ -29,11 +29,6 @@ export default class drinkWaterUnit extends BaseModel {
allowNull: false,
desc: "نام دانشگاه",
},
workflowId: {
type: this.DataTypes.INTEGER,
allowNull: true,
desc: "شناسه روند کار",
},
};
add = Object.keys(_.omit(this.schema, ["id"]));

Loading…
Cancel
Save