@brontosaurus/db
Version:
:ocean: Schema for brontosaurus
80 lines (79 loc) • 3.54 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.getOrganizationsByRawPage = exports.getActiveOrganizationsByRawPage = exports.getOrganizationPagesByRawKeyword = exports.getActiveOrganizationPagesByRawKeyword = exports.getOrganizationByRawNames = exports.getOrganizationByRawName = void 0;
const organization_1 = require("../model/organization");
const getOrganizationByRawName = (name) => __awaiter(void 0, void 0, void 0, function* () {
return yield organization_1.OrganizationModel.findOne({
name,
});
});
exports.getOrganizationByRawName = getOrganizationByRawName;
const getOrganizationByRawNames = (names) => __awaiter(void 0, void 0, void 0, function* () {
return yield organization_1.OrganizationModel.find({
name: {
$in: names,
},
});
});
exports.getOrganizationByRawNames = getOrganizationByRawNames;
const getActiveOrganizationPagesByRawKeyword = (limit, keyword) => __awaiter(void 0, void 0, void 0, function* () {
const regexp = new RegExp(keyword, 'i');
return (yield organization_1.OrganizationModel.countDocuments({
name: {
$regex: regexp,
},
active: true,
})) / limit;
});
exports.getActiveOrganizationPagesByRawKeyword = getActiveOrganizationPagesByRawKeyword;
const getOrganizationPagesByRawKeyword = (limit, keyword) => __awaiter(void 0, void 0, void 0, function* () {
const regexp = new RegExp(keyword, 'i');
return (yield organization_1.OrganizationModel.countDocuments({
name: {
$regex: regexp,
},
})) / limit;
});
exports.getOrganizationPagesByRawKeyword = getOrganizationPagesByRawKeyword;
const getActiveOrganizationsByRawPage = (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 organizations = yield organization_1.OrganizationModel.find({
name: {
$regex: regexp,
},
active: true,
}).skip(page * limit).limit(limit).sort({ _id: -1 });
return organizations;
});
exports.getActiveOrganizationsByRawPage = getActiveOrganizationsByRawPage;
const getOrganizationsByRawPage = (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 organizations = yield organization_1.OrganizationModel.find({
name: {
$regex: regexp,
},
}).skip(page * limit).limit(limit).sort({ _id: -1 });
return organizations;
});
exports.getOrganizationsByRawPage = getOrganizationsByRawPage;