石墨消解仪后端用nodejs编写,与嵌入式端交互和前端交互均用ws
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

44 lines
985 B

const Variety = require("../model/variety.model");
class VarietyService {
async getAllVariety() {
const res = await Variety.findAll();
const arr = res.map((item) => item.dataValues);
return arr;
}
async getVarietyById(id) {
const whereOpt = {};
id && Object.assign(whereOpt, { id });
const res = await Variety.findOne({
where: whereOpt,
});
return res ? res.dataValues : null;
}
async getVarietyByName(variety_name) {
const whereOpt = {};
variety_name && Object.assign(whereOpt, { variety_name });
const res = await Variety.findOne({
where: whereOpt,
});
return res ? res.dataValues : null;
}
async addVariety(variety_name) {
const res = await Variety.create({
variety_name,
});
return res?.dataValues;
}
async deleteVarietyById(id) {
const res = await Variety.destroy({
where: {
id,
},
});
return res;
}
}
module.exports = new VarietyService();