@brontosaurus/db
Version:
:ocean: Schema for brontosaurus
80 lines (79 loc) • 3.24 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getGroupsByRawPage = exports.getActiveGroupsByRawPage = exports.getGroupPagesByRawKeyword = exports.getActiveGroupPagesByRawKeyword = exports.getGroupByRawNames = exports.getGroupByRawName = void 0;
const group_1 = require("../model/group");
const getGroupByRawName = (name) => __awaiter(void 0, void 0, void 0, function* () {
return yield group_1.GroupModel.findOne({
name,
});
});
exports.getGroupByRawName = getGroupByRawName;
const getGroupByRawNames = (names) => __awaiter(void 0, void 0, void 0, function* () {
return yield group_1.GroupModel.find({
name: {
$in: names,
},
});
});
exports.getGroupByRawNames = getGroupByRawNames;
const getActiveGroupPagesByRawKeyword = (limit, keyword) => __awaiter(void 0, void 0, void 0, function* () {
const regexp = new RegExp(keyword, 'i');
return (yield group_1.GroupModel.countDocuments({
name: {
$regex: regexp,
},
active: true,
})) / limit;
});
exports.getActiveGroupPagesByRawKeyword = getActiveGroupPagesByRawKeyword;
const getGroupPagesByRawKeyword = (limit, keyword) => __awaiter(void 0, void 0, void 0, function* () {
const regexp = new RegExp(keyword, 'i');
return (yield group_1.GroupModel.countDocuments({
name: {
$regex: regexp,
},
})) / limit;
});
exports.getGroupPagesByRawKeyword = getGroupPagesByRawKeyword;
const getActiveGroupsByRawPage = (keyword, limit, page) => __awaiter(void 0, void 0, void 0, function* () {
if (page < 0) {
return [];
}
if (limit < 1) {
return [];
}
const regexp = new RegExp(keyword, 'i');
const groups = yield group_1.GroupModel.find({
name: {
$regex: regexp,
},
active: true,
}).skip(page * limit).limit(limit).sort({ _id: -1 });
return groups;
});
exports.getActiveGroupsByRawPage = getActiveGroupsByRawPage;
const getGroupsByRawPage = (keyword, limit, page) => __awaiter(void 0, void 0, void 0, function* () {
if (page < 0) {
return [];
}
if (limit < 1) {
return [];
}
const regexp = new RegExp(keyword, 'i');
const groups = yield group_1.GroupModel.find({
name: {
$regex: regexp,
},
}).skip(page * limit).limit(limit).sort({ _id: -1 });
return groups;
});
exports.getGroupsByRawPage = getGroupsByRawPage;