明树Git Lab

Commit d63dec1c authored by zfp1's avatar zfp1

update

parent e1a26041
......@@ -5,7 +5,7 @@
async function findCompInfo(req, res, next) {
try {
let ret = await DB.CompanyInfo.findOne({}).populate({path: "companyInfoImgs"}).populate({path: "qualiCertiImgs"}).populate({path: "addressInfo.img"}).populate({ path: "gcImg" }).populate({ path: "jdImg" }).lean().exec();
let ret = await DB.CompanyInfo.findOne({}).populate({ path: "companyInfoImgs" }).populate({ path: "qualiCertiImgs" }).populate({ path: "addressInfo.img" }).populate({ path: "gcImg" }).populate({ path: "jdImg" }).lean().exec();
return res.sendData(ret);
} catch (error) {
next(error);
......@@ -15,8 +15,8 @@ async function findCompInfo(req, res, next) {
async function updateCompInfo(req, res, next) {
try {
let body = req.body;
body.companyInfoImgs = (body.companyInfoImgs || []).map(o => {return o && o._id || o});
body.qualiCertiImgs = (body.qualiCertiImgs || []).map(o => {return o && o._id || o});
body.companyInfoImgs = (body.companyInfoImgs || []).map(o => { return o && o._id || o });
body.qualiCertiImgs = (body.qualiCertiImgs || []).map(o => { return o && o._id || o });
body.addressInfo = body.addressInfo || [];
let newAdr = [];
for (let index = 0; index < body.addressInfo.length; index++) {
......@@ -26,7 +26,7 @@ async function updateCompInfo(req, res, next) {
}
body.addressInfo = newAdr;
console.log(body, "===========================")
let ret = await DB.CompanyInfo.findOneAndUpdate({_id: body._id},body);
let ret = await DB.CompanyInfo.findOneAndUpdate({ _id: body._id }, body);
return res.sendData(ret);
} catch (error) {
......@@ -36,8 +36,52 @@ async function updateCompInfo(req, res, next) {
async function createSccj(req, res, next) {
try {
let ret = await DB.Sccj.create(req.body)
res.sendData(ret);
} catch (error) {
next(error)
}
}
async function updateSccj(req, res, next) {
try {
let updateInfo = {
...req.body,
}
let ret = await DB.Sccj.findOneAndUpdate({ _id: req.body._id }, updateInfo);
res.sendData(ret);
} catch (error) {
next(error)
}
}
async function delSccj(req, res, next) {
try {
let ret = await DB.Sccj.findOneAndUpdate({ _id: req.body._id }, { del: 1 });
res.sendData(ret);
} catch (error) {
next(error)
}
}
async function getSccjList(req, res, next) {
try {
let search = { del: 0 };
let page = req.body.page || 1;
let pageSize = req.body.pageSize || 10;
let skip = (page - 1) * pageSize;
if (req.body.name) {
search.name = req.body.name;
}
let count = await DB.Sccj.countDocuments(search)
let list = await DB.Sccj.find(search).skip(skip).limit(pageSize).sort({ order: 1}).lean().exec();
res.sendData({ count, list });
} catch (error) {
next(error)
}
}
......@@ -45,5 +89,8 @@ async function updateCompInfo(req, res, next) {
module.exports = {
findCompInfo,
updateCompInfo,
createSccj,
updateSccj,
delSccj,
getSccjList,
}
\ No newline at end of file
......@@ -88,6 +88,7 @@ const PackMatOutList = require("./models/letianPackMatOutList");
const SuppFact = require("./models/letianSuppFact");
const TechProcess = require("./models/letianTechProcess");
const Sccj = require("./models/letianSccj");
global.DB = {
File,
......@@ -145,6 +146,7 @@ global.DB = {
SuppFact,
TechProcess,
ProductLt,
Sccj,
}
......
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const moment = require('moment');
// const autoIncrement = require('mongoose-auto-increment');
// autoIncrement.initialize(mongoose.connection);
/**
* //营养成分表
*/
const letianSccjSchema = new Schema({
name: {
type: String,
comment: "名称",
},
order: Number,
creator: {
type: mongoose.Types.ObjectId,
ref: 'User',
comment1: "创建人"
},
createdAt: {
type: Date,
default: Date.now,
get: v => moment(v).format("YYYY-MM-DD HH:mm:ss"),
},
updatedAt: {
type: Date,
default: Date.now,
get: v => moment(v).format("YYYY-MM-DD HH:mm:ss"),
},
del: {
type: Number,
default: 0,
comment1: '默认0 , 1:表示删除, 若有其他隐藏业务 不要混用此字段。'
}
}, {
toJSON: {
getters: true
}
});
const Sccj = mongoose.model('Sccj', letianSccjSchema, 'letianSccj');
module.exports = Sccj;
\ No newline at end of file
......@@ -10,4 +10,10 @@ router.post('/info', companyInfoController.findCompInfo);
router.post('/update', companyInfoController.updateCompInfo);
router.post('/sccj/create', companyInfoController.createSccj);
router.post('/sccj/update', companyInfoController.updateSccj);
router.post('/sccj/delete', companyInfoController.delSccj);
router.post('/sccj/list', companyInfoController.getSccjList);
module.exports = router;
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment