forked from nghianv/luffymoongodb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRepositoryBase.js
34 lines (34 loc) · 1.38 KB
/
RepositoryBase.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var mongoose = require("mongoose");
var RepositoryBase = /** @class */ (function () {
function RepositoryBase(schemaModel) {
this._model = schemaModel;
}
RepositoryBase.prototype.create = function (item, callback) {
this._model.create(item, callback);
};
RepositoryBase.prototype.retrieve = function (callback) {
this._model.find({}, callback);
};
RepositoryBase.prototype.update = function (_id, item, callback) {
this._model.update({ _id: _id }, item, callback);
};
RepositoryBase.prototype.delete = function (_id, callback) {
this._model.remove({ _id: this.toObjectId(_id) }, function (err) { return callback(err, null); });
};
RepositoryBase.prototype.findById = function (_id, callback) {
this._model.findById(_id, callback);
};
RepositoryBase.prototype.findOne = function (conditions, callback) {
this._model.findOne(conditions, callback);
};
RepositoryBase.prototype.find = function (cond, fields, options, callback) {
this._model.find(cond, options, callback);
};
RepositoryBase.prototype.toObjectId = function (_id) {
return mongoose.Types.ObjectId.createFromHexString(_id);
};
return RepositoryBase;
}());
exports.RepositoryBase = RepositoryBase;