You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Hydro/module/module-pastebin/model.js

27 lines
638 B
JavaScript

5 years ago
const { DocumentNotFoundError } = global.Hydro.error;
const { db } = global.Hydro.service;
const coll = db.collection('pastebin');
async function add({
owner, language, expire, password, title, content,
}) {
const doc = {
owner, password, expire, language, title, content,
};
const res = await coll.insertOne(doc);
return res.insertedId;
}
async function get(_id) {
const doc = await coll.findOne({ _id });
if (!doc) throw new DocumentNotFoundError(_id);
return doc;
}
function del(_id) {
return coll.deleteOne({ _id });
}
global.Hydro.model.pastebin = module.exports = { add, get, del };