diff --git a/drinkWaterUnitAPI.js b/drinkWaterUnitAPI.js index c372ad8..bf083db 100644 --- a/drinkWaterUnitAPI.js +++ b/drinkWaterUnitAPI.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, { diff --git a/drinkWaterUnitModel.js b/drinkWaterUnitModel.js index ace2ab8..992a362 100644 --- a/drinkWaterUnitModel.js +++ b/drinkWaterUnitModel.js @@ -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"]));