ldk-software
v1.0.6
Published
A package! made by LDK Team
Downloads
39
Maintainers
Readme
HƯỚNG DẪN SỬ DỤNG TRƯỚC KHI DÙNG
Khởi tạo kết nối và auto require routing
Copy & Paste www/routing/authorization.js
let path = require('path');
let { initRoutings } = require('ldk-software/utils');
let BASE_COLL = require('../database/intalize/base-coll');
require('ldk-software/intalize/base-coll')(BASE_COLL);
let folderRouting = path.resolve(__dirname, './role/');
let initAuths = initRoutings(folderRouting);
Những hàm hữu ích
Utils: ldk-software/utils
const { initRoutings, convertToSlug, isRequired } = require('ldk-software/utils');
Những models, collections có sẵn và sẽ còn cập nhật...
// BLOGS (MODEL, COLLECTIONS)
const { CATEGORY_COLL, CATEGORY_MODEL } = require('ldk-software/blogs/categories');
const { COMMENT_COLL, COMMENT_MODEL } = require('ldk-software/blogs/comments');
const { IMAGE_COLL, IMAGE_MODEL } = require('ldk-software/blogs/images');
const { POST_COLL, POST_MODEL } = require('ldk-software/blogs/posts');
const { USER_COLL, USER_MODEL } = require('ldk-software/blogs/users');
// PERMISSIONS (MODEL, COLLECTIONS)
const { USER_COLL, USER_MODEL } = require('ldk-software/permissions/users');
const { GROUP_COLL, GROUP_MODEL } = require('ldk-software/permissions/groups');
Cách kế thừa model
Tạo file ở thư mục model www/models
"use strict";
/**
* EXTERNAL PAKCAGE
*/
const ObjectID = require('mongoose').Types.ObjectId;
const jwt = require('jsonwebtoken');
const { hash, hashSync, compare } = require('bcryptjs');
/**
* INTERNAL PAKCAGE
*/
const cfJWS = require('../config/cf_jws');
/**
* BASE
*/
const { USER_MODEL_BASE } = require('ldk-software/blogs/users');
/**
* COLLECTIONS
*/
const { USER_COLL } = require('ldk-software/blogs/users');
// Có sẵn những hàm trong BaseModel và USER_MODE_BASE (insert, deleteUser, updateUser, getInfo, getListUsers, signIn)
class Model extends USER_MODEL_BASE {
constructor() {
super(USER_COLL);
}
// Hàm mới...
getListUsersSorted() {
return new Promise(async resolve => {
try {
const listUserSorted = await USER_COLL.find({}).sort({ createAt: -1 });
if(!listUserSorted)
return resolve({ error: true, message: "list_user_null" });
return resolve({ error: false, data: listUserSorted });
} catch (error) {
return resolve({ error: true, message: error.message });
}
})
}
}
exports.MODEL = new Model;