Skip to content

Instantly share code, notes, and snippets.

@DingWeizhe
Created April 8, 2019 10:02
Show Gist options
  • Save DingWeizhe/0ce875c22324744b1d101bc04710accd to your computer and use it in GitHub Desktop.
Save DingWeizhe/0ce875c22324744b1d101bc04710accd to your computer and use it in GitHub Desktop.
const api = {
addProduct: async function (req, res, next) {
const newId = await this.getNewId();
res.send(newId);
},
getNewId: async function (){
const { collection } = await connectDB('product_detail');
const result = await promisify(
collection
.find()
.project({ product_id: 1 })
.sort({ product_id: -1 })
.limit(1)
.toArray
)();
const newId = Number(result[0].product_id) + 1;
return newId;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment