//保存请假申请 async save(leaveApply) { var mongodb = await MongoClient.connect(mongosettingsurl); var dbase = mongodb.db(mongosettingsdb); var collection = dbase.collection("leave_apply"); const obj = await this.get(leaveApply.id) if (!obj) { await collection.insertOne(leaveApply) } else { await collection.deleteMany({ id: leaveApply.id }) await collection.insertOne(leaveApply) } mongodb.close() }
//删除请假申请 async remove(id) { var mongodb = await MongoClient.connect(mongosettingsurl); var dbase = mongodb.db(mongosettingsdb); var collection = dbase.collection("leave_apply"); await collection.deleteMany({ id: id }) mongodb.close() }
//根据id获取请假申请 async get(id) { var mongodb = await MongoClient.connect(mongosettingsurl); var dbase = mongodb.db(mongosettingsdb); var collection = dbase.collection("leave_apply"); var instance = await collection.findOne({ id: id }) const obj = instance ? LeaveApply.fromJSON(instance) : null mongodb.close() return obj }
async getItems(condition){ var mongodb = await MongoClient.connect(mongosettingsurl); var dbase = mongodb.db(mongosettingsdb); var collection = dbase.collection("leave_apply");