Created
April 8, 2019 10:02
-
-
Save DingWeizhe/0ce875c22324744b1d101bc04710accd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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