@brontosaurus/db
Version:
:ocean: Schema for brontosaurus
72 lines (71 loc) • 3.08 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.getAccountsByRawPage = exports.getActiveAccountsByRawPage = exports.getAccountPagesByRawKeyword = exports.getActiveAccountPagesByRawKeyword = exports.getAccountByRawUsername = void 0;
const account_1 = require("../model/account");
const getAccountByRawUsername = (username) => __awaiter(void 0, void 0, void 0, function* () {
return yield account_1.AccountModel.findOne({
username,
});
});
exports.getAccountByRawUsername = getAccountByRawUsername;
const getActiveAccountPagesByRawKeyword = (limit, keyword) => __awaiter(void 0, void 0, void 0, function* () {
const regexp = new RegExp(keyword, 'i');
return (yield account_1.AccountModel.countDocuments({
username: {
$regex: regexp,
},
active: true,
})) / limit;
});
exports.getActiveAccountPagesByRawKeyword = getActiveAccountPagesByRawKeyword;
const getAccountPagesByRawKeyword = (limit, keyword) => __awaiter(void 0, void 0, void 0, function* () {
const regexp = new RegExp(keyword, 'i');
return (yield account_1.AccountModel.countDocuments({
username: {
$regex: regexp,
},
})) / limit;
});
exports.getAccountPagesByRawKeyword = getAccountPagesByRawKeyword;
const getActiveAccountsByRawPage = (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 accounts = yield account_1.AccountModel.find({
username: {
$regex: regexp,
},
active: true,
}).skip(page * limit).limit(limit).sort({ _id: -1 });
return accounts;
});
exports.getActiveAccountsByRawPage = getActiveAccountsByRawPage;
const getAccountsByRawPage = (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 accounts = yield account_1.AccountModel.find({
username: {
$regex: regexp,
},
}).skip(page * limit).limit(limit).sort({ _id: -1 });
return accounts;
});
exports.getAccountsByRawPage = getAccountsByRawPage;