@drax/identity-back 0.1.8 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/graphql/resolvers/role.resolvers.js +1 -1
- package/dist/graphql/resolvers/tenant.resolvers.js +1 -1
- package/dist/graphql/resolvers/user-api-key.resolvers.js +1 -1
- package/dist/graphql/resolvers/user.resolvers.js +2 -2
- package/dist/repository/mongo/RoleMongoRepository.js +5 -2
- package/dist/repository/mongo/TenantMongoRepository.js +5 -2
- package/dist/repository/mongo/UserApiKeyMongoRepository.js +5 -16
- package/dist/repository/mongo/UserMongoRepository.js +5 -16
- package/dist/repository/sqlite/RoleSqliteRepository.js +5 -2
- package/dist/repository/sqlite/TenantSqliteRepository.js +5 -2
- package/dist/repository/sqlite/UserApiKeySqliteRepository.js +6 -18
- package/dist/repository/sqlite/UserSqliteRepository.js +6 -19
- package/dist/routes/RoleRoutes.js +2 -2
- package/dist/routes/TenantRoutes.js +2 -2
- package/dist/routes/UserApiKeyRoutes.js +2 -2
- package/dist/routes/UserRoutes.js +3 -3
- package/dist/services/RoleService.js +2 -2
- package/dist/services/TenantService.js +2 -2
- package/dist/services/UserApiKeyService.js +2 -2
- package/dist/services/UserService.js +2 -2
- package/package.json +5 -5
- package/src/graphql/resolvers/role.resolvers.ts +1 -1
- package/src/graphql/resolvers/tenant.resolvers.ts +1 -1
- package/src/graphql/resolvers/user-api-key.resolvers.ts +1 -1
- package/src/graphql/resolvers/user.resolvers.ts +2 -2
- package/src/repository/mongo/RoleMongoRepository.ts +8 -4
- package/src/repository/mongo/TenantMongoRepository.ts +8 -4
- package/src/repository/mongo/UserApiKeyMongoRepository.ts +6 -16
- package/src/repository/mongo/UserMongoRepository.ts +12 -16
- package/src/repository/sqlite/RoleSqliteRepository.ts +12 -2
- package/src/repository/sqlite/TenantSqliteRepository.ts +6 -2
- package/src/repository/sqlite/UserApiKeySqliteRepository.ts +7 -18
- package/src/repository/sqlite/UserSqliteRepository.ts +13 -20
- package/src/routes/RoleRoutes.ts +2 -2
- package/src/routes/TenantRoutes.ts +2 -2
- package/src/routes/UserApiKeyRoutes.ts +2 -2
- package/src/routes/UserRoutes.ts +3 -3
- package/src/services/RoleService.ts +2 -2
- package/src/services/TenantService.ts +2 -2
- package/src/services/UserApiKeyService.ts +2 -2
- package/src/services/UserService.ts +2 -2
- package/tsconfig.tsbuildinfo +1 -1
- package/types/graphql/resolvers/role.resolvers.d.ts +1 -1
- package/types/graphql/resolvers/tenant.resolvers.d.ts +1 -1
- package/types/graphql/resolvers/user-api-key.resolvers.d.ts +1 -1
- package/types/graphql/resolvers/user.resolvers.d.ts +1 -1
- package/types/repository/mongo/RoleMongoRepository.d.ts +1 -1
- package/types/repository/mongo/RoleMongoRepository.d.ts.map +1 -1
- package/types/repository/mongo/TenantMongoRepository.d.ts +1 -1
- package/types/repository/mongo/TenantMongoRepository.d.ts.map +1 -1
- package/types/repository/mongo/UserApiKeyMongoRepository.d.ts +1 -1
- package/types/repository/mongo/UserApiKeyMongoRepository.d.ts.map +1 -1
- package/types/repository/mongo/UserMongoRepository.d.ts +1 -1
- package/types/repository/mongo/UserMongoRepository.d.ts.map +1 -1
- package/types/repository/sqlite/RoleSqliteRepository.d.ts +1 -1
- package/types/repository/sqlite/RoleSqliteRepository.d.ts.map +1 -1
- package/types/repository/sqlite/TenantSqliteRepository.d.ts +1 -1
- package/types/repository/sqlite/TenantSqliteRepository.d.ts.map +1 -1
- package/types/repository/sqlite/UserApiKeySqliteRepository.d.ts +1 -1
- package/types/repository/sqlite/UserApiKeySqliteRepository.d.ts.map +1 -1
- package/types/repository/sqlite/UserSqliteRepository.d.ts +1 -1
- package/types/repository/sqlite/UserSqliteRepository.d.ts.map +1 -1
- package/types/services/RoleService.d.ts +1 -1
- package/types/services/RoleService.d.ts.map +1 -1
- package/types/services/TenantService.d.ts +1 -1
- package/types/services/TenantService.d.ts.map +1 -1
- package/types/services/UserApiKeyService.d.ts +1 -1
- package/types/services/UserApiKeyService.d.ts.map +1 -1
- package/types/services/UserService.d.ts +1 -1
- package/types/services/UserService.d.ts.map +1 -1
|
@@ -64,7 +64,7 @@ export default {
|
|
|
64
64
|
throw new GraphQLError('error.server');
|
|
65
65
|
}
|
|
66
66
|
},
|
|
67
|
-
paginateRole: async (_, { options = { page: 1, limit: 5, orderBy: "",
|
|
67
|
+
paginateRole: async (_, { options = { page: 1, limit: 5, orderBy: "", order: false, search: "", filters: [] } }, { rbac }) => {
|
|
68
68
|
try {
|
|
69
69
|
rbac.assertPermission(IdentityPermissions.ViewRole);
|
|
70
70
|
const roleService = RoleServiceFactory();
|
|
@@ -50,7 +50,7 @@ export default {
|
|
|
50
50
|
throw new GraphQLError('error.server');
|
|
51
51
|
}
|
|
52
52
|
},
|
|
53
|
-
paginateTenant: async (_, { options = { page: 1, limit: 5, orderBy: "",
|
|
53
|
+
paginateTenant: async (_, { options = { page: 1, limit: 5, orderBy: "", order: false, search: "", filters: [] } }, { rbac }) => {
|
|
54
54
|
try {
|
|
55
55
|
rbac.assertPermission(IdentityPermissions.ViewTenant);
|
|
56
56
|
const tenantService = TenantServiceFactory();
|
|
@@ -6,7 +6,7 @@ import UnauthorizedError from "../../errors/UnauthorizedError.js";
|
|
|
6
6
|
import * as crypto from "node:crypto";
|
|
7
7
|
export default {
|
|
8
8
|
Query: {
|
|
9
|
-
paginateUserApiKey: async (_, { options = { page: 1, limit: 5, orderBy: "",
|
|
9
|
+
paginateUserApiKey: async (_, { options = { page: 1, limit: 5, orderBy: "", order: false, search: "", filters: [] } }, { rbac, authUser }) => {
|
|
10
10
|
try {
|
|
11
11
|
rbac.assertAuthenticated();
|
|
12
12
|
rbac.assertOrPermissions([
|
|
@@ -38,7 +38,7 @@ export default {
|
|
|
38
38
|
throw new GraphQLError('error.server');
|
|
39
39
|
}
|
|
40
40
|
},
|
|
41
|
-
paginateUser: async (_, { options = { page: 1, limit: 5, orderBy: "",
|
|
41
|
+
paginateUser: async (_, { options = { page: 1, limit: 5, orderBy: "", order: false, search: "", filters: [] } }, { rbac }) => {
|
|
42
42
|
try {
|
|
43
43
|
rbac.assertPermission(IdentityPermissions.ViewUser);
|
|
44
44
|
let userService = UserServiceFactory();
|
|
@@ -46,7 +46,7 @@ export default {
|
|
|
46
46
|
options.filters = [];
|
|
47
47
|
}
|
|
48
48
|
if (rbac.getAuthUser.tenantId) {
|
|
49
|
-
options.filters.push({ field: 'tenant', operator: '
|
|
49
|
+
options.filters.push({ field: 'tenant', operator: 'eq', value: rbac.getAuthUser.tenantId });
|
|
50
50
|
}
|
|
51
51
|
return await userService.paginate(options);
|
|
52
52
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { RoleModel } from "../../models/RoleModel.js";
|
|
2
|
+
import { MongooseQueryFilter, MongooseSort } from "@drax/common-back";
|
|
2
3
|
class RoleMongoRepository {
|
|
3
4
|
async create(roleData) {
|
|
4
5
|
const role = new RoleModel(roleData);
|
|
@@ -26,14 +27,16 @@ class RoleMongoRepository {
|
|
|
26
27
|
const roles = await RoleModel.find().populate('childRoles').exec();
|
|
27
28
|
return roles;
|
|
28
29
|
}
|
|
29
|
-
async paginate({ page = 1, limit = 5, orderBy = '',
|
|
30
|
+
async paginate({ page = 1, limit = 5, orderBy = '', order = false, search = '', filters = [] }) {
|
|
30
31
|
const query = {};
|
|
31
32
|
if (search) {
|
|
32
33
|
query['$or'] = [
|
|
33
34
|
{ name: new RegExp(search, 'i') },
|
|
34
35
|
];
|
|
35
36
|
}
|
|
36
|
-
|
|
37
|
+
MongooseQueryFilter.applyFilters(query, filters);
|
|
38
|
+
const sort = MongooseSort.applySort(orderBy, order);
|
|
39
|
+
const options = { populate: ['childRoles'], page, limit, sort };
|
|
37
40
|
const roles = await RoleModel.paginate(query, options);
|
|
38
41
|
return {
|
|
39
42
|
page: page,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { TenantModel } from "../../models/TenantModel.js";
|
|
2
|
+
import { MongooseSort, MongooseQueryFilter } from "@drax/common-back";
|
|
2
3
|
class TenantMongoRepository {
|
|
3
4
|
async create(tenantData) {
|
|
4
5
|
const tenant = new TenantModel(tenantData);
|
|
@@ -25,14 +26,16 @@ class TenantMongoRepository {
|
|
|
25
26
|
const tenants = await TenantModel.find().exec();
|
|
26
27
|
return tenants;
|
|
27
28
|
}
|
|
28
|
-
async paginate({ page = 1, limit = 5, orderBy = '',
|
|
29
|
+
async paginate({ page = 1, limit = 5, orderBy = '', order = false, search = '', filters = [] }) {
|
|
29
30
|
const query = {};
|
|
30
31
|
if (search) {
|
|
31
32
|
query['$or'] = [
|
|
32
33
|
{ name: new RegExp(search, 'i') },
|
|
33
34
|
];
|
|
34
35
|
}
|
|
35
|
-
|
|
36
|
+
MongooseQueryFilter.applyFilters(query, filters);
|
|
37
|
+
const sort = MongooseSort.applySort(orderBy, order);
|
|
38
|
+
const options = { page, limit, sort };
|
|
36
39
|
const tenants = await TenantModel.paginate(query, options);
|
|
37
40
|
return {
|
|
38
41
|
page: page,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UserApiKeyModel } from "../../models/UserApiKeyModel.js";
|
|
2
|
-
import { mongoose, MongooseErrorToValidationError, MongoServerErrorToValidationError } from "@drax/common-back";
|
|
2
|
+
import { mongoose, MongooseErrorToValidationError, MongooseQueryFilter, MongooseSort, MongoServerErrorToValidationError } from "@drax/common-back";
|
|
3
3
|
import { MongoServerError } from "mongodb";
|
|
4
4
|
class UserMongoRepository {
|
|
5
5
|
constructor() {
|
|
@@ -47,7 +47,7 @@ class UserMongoRepository {
|
|
|
47
47
|
const userApiKey = await UserApiKeyModel.findOne({ secret: { $eq: secret }, deleted: { $ne: true } }).populate({ path: 'user', populate: { path: 'tenant role' } }).exec();
|
|
48
48
|
return userApiKey;
|
|
49
49
|
}
|
|
50
|
-
async paginate({ page = 1, limit = 5, orderBy = '',
|
|
50
|
+
async paginate({ page = 1, limit = 5, orderBy = '', order = false, search = '', filters = [] }) {
|
|
51
51
|
const query = {
|
|
52
52
|
deleted: false
|
|
53
53
|
};
|
|
@@ -56,20 +56,9 @@ class UserMongoRepository {
|
|
|
56
56
|
{ name: new RegExp(search, 'i') },
|
|
57
57
|
];
|
|
58
58
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
query[filter.field] = { $eq: filter.value };
|
|
63
|
-
}
|
|
64
|
-
if (['ne', '$ne'].includes(filter.operator)) {
|
|
65
|
-
query[filter.field] = { $ne: filter.value };
|
|
66
|
-
}
|
|
67
|
-
if (['in', '$in'].includes(filter.operator)) {
|
|
68
|
-
query[filter.field] = { $in: filter.value };
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
const options = { populate: ['user', 'user.tenant', 'user.role'], page: page, limit: limit };
|
|
59
|
+
MongooseQueryFilter.applyFilters(query, filters);
|
|
60
|
+
const sort = MongooseSort.applySort(orderBy, order);
|
|
61
|
+
const options = { populate: ['user', 'user.tenant', 'user.role'], page, limit, sort };
|
|
73
62
|
const userApiKeyPaginated = await UserApiKeyModel.paginate(query, options);
|
|
74
63
|
return {
|
|
75
64
|
page: page,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UserModel } from "../../models/UserModel.js";
|
|
2
|
-
import { mongoose, MongooseErrorToValidationError, MongoServerErrorToValidationError, ValidationError } from "@drax/common-back";
|
|
2
|
+
import { mongoose, MongooseErrorToValidationError, MongooseQueryFilter, MongooseSort, MongoServerErrorToValidationError, ValidationError } from "@drax/common-back";
|
|
3
3
|
import { MongoServerError } from "mongodb";
|
|
4
4
|
import RoleMongoRepository from "./RoleMongoRepository.js";
|
|
5
5
|
class UserMongoRepository {
|
|
@@ -50,7 +50,7 @@ class UserMongoRepository {
|
|
|
50
50
|
const user = await UserModel.findOne({ username: username }).populate(['role', 'tenant']).exec();
|
|
51
51
|
return user;
|
|
52
52
|
}
|
|
53
|
-
async paginate({ page = 1, limit = 5, orderBy = '',
|
|
53
|
+
async paginate({ page = 1, limit = 5, orderBy = '', order = false, search = '', filters = [] }) {
|
|
54
54
|
const query = {};
|
|
55
55
|
if (search) {
|
|
56
56
|
query['$or'] = [
|
|
@@ -59,20 +59,9 @@ class UserMongoRepository {
|
|
|
59
59
|
{ name: new RegExp(search, 'i') },
|
|
60
60
|
];
|
|
61
61
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
query[filter.field] = { $eq: filter.value };
|
|
66
|
-
}
|
|
67
|
-
if (['ne', '$ne'].includes(filter.operator)) {
|
|
68
|
-
query[filter.field] = { $ne: filter.value };
|
|
69
|
-
}
|
|
70
|
-
if (['in', '$in'].includes(filter.operator)) {
|
|
71
|
-
query[filter.field] = { $in: filter.value };
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
const options = { populate: ['role', 'tenant'], page: page, limit: limit };
|
|
62
|
+
MongooseQueryFilter.applyFilters(query, filters);
|
|
63
|
+
const sort = MongooseSort.applySort(orderBy, order);
|
|
64
|
+
const options = { populate: ['role', 'tenant'], page, limit, sort };
|
|
76
65
|
const userPaginated = await UserModel.paginate(query, options);
|
|
77
66
|
return {
|
|
78
67
|
page: page,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import sqlite from "better-sqlite3";
|
|
2
2
|
import { randomUUID } from "node:crypto";
|
|
3
|
-
import { SqliteErrorToValidationError, SqliteTableBuilder } from "@drax/common-back";
|
|
3
|
+
import { SqliteErrorToValidationError, SqliteTableBuilder, SqlQueryFilter, SqlSort } from "@drax/common-back";
|
|
4
4
|
const tableFields = [
|
|
5
5
|
{ name: "name", type: "TEXT", unique: true, primary: false },
|
|
6
6
|
{ name: "permissions", type: "TEXT", unique: false, primary: false },
|
|
@@ -67,13 +67,16 @@ class RoleSqliteRepository {
|
|
|
67
67
|
throw SqliteErrorToValidationError(e, roleData);
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
|
-
async paginate({ page = 1, limit = 5, orderBy = '',
|
|
70
|
+
async paginate({ page = 1, limit = 5, orderBy = '', order = false, search = '', filters = [] }) {
|
|
71
71
|
const offset = page > 1 ? (page - 1) * limit : 0;
|
|
72
72
|
let where = "";
|
|
73
73
|
if (search) {
|
|
74
74
|
where = ` WHERE name LIKE '%${search}%'`;
|
|
75
75
|
}
|
|
76
|
+
where = SqlQueryFilter.applyFilters(where, filters);
|
|
77
|
+
const sort = SqlSort.applySort(orderBy, order);
|
|
76
78
|
const rCount = this.db.prepare('SELECT COUNT(*) as count FROM roles' + where).get();
|
|
79
|
+
where += sort;
|
|
77
80
|
const roles = this.db.prepare('SELECT * FROM roles ' + where + ' LIMIT ? OFFSET ?').all([limit, offset]);
|
|
78
81
|
for (const role of roles) {
|
|
79
82
|
await this.populateRole(role);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import sqlite from "better-sqlite3";
|
|
2
2
|
import { randomUUID } from "node:crypto";
|
|
3
|
-
import { SqliteErrorToValidationError, SqliteTableBuilder } from "@drax/common-back";
|
|
3
|
+
import { SqliteErrorToValidationError, SqliteTableBuilder, SqlQueryFilter, SqlSort } from "@drax/common-back";
|
|
4
4
|
const tableFields = [
|
|
5
5
|
{ name: "name", type: "TEXT", unique: false, primary: false },
|
|
6
6
|
{ name: "createdAt", type: "TEXT", unique: false, primary: false },
|
|
@@ -78,13 +78,16 @@ class TenantSqliteRepository {
|
|
|
78
78
|
}
|
|
79
79
|
return tenants;
|
|
80
80
|
}
|
|
81
|
-
async paginate({ page = 1, limit = 5, orderBy = '',
|
|
81
|
+
async paginate({ page = 1, limit = 5, orderBy = '', order = false, search = '', filters = [] }) {
|
|
82
82
|
const offset = page > 1 ? (page - 1) * limit : 0;
|
|
83
83
|
let where = "";
|
|
84
84
|
if (search) {
|
|
85
85
|
where = ` WHERE name LIKE '%${search}%'`;
|
|
86
86
|
}
|
|
87
|
+
where = SqlQueryFilter.applyFilters(where, filters);
|
|
88
|
+
const sort = SqlSort.applySort(orderBy, order);
|
|
87
89
|
const rCount = this.db.prepare('SELECT COUNT(*) as count FROM tenants' + where).get();
|
|
90
|
+
where += sort;
|
|
88
91
|
const tenants = this.db.prepare('SELECT * FROM tenants ' + where + ' LIMIT ? OFFSET ?').all([limit, offset]);
|
|
89
92
|
return {
|
|
90
93
|
page: page,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import sqlite from "better-sqlite3";
|
|
2
2
|
import { randomUUID } from "node:crypto";
|
|
3
|
-
import { SqliteErrorToValidationError, SqliteTableBuilder } from "@drax/common-back";
|
|
3
|
+
import { SqliteErrorToValidationError, SqliteTableBuilder, SqlQueryFilter, SqlSort } from "@drax/common-back";
|
|
4
4
|
import UserSqliteRepository from "./UserSqliteRepository.js";
|
|
5
5
|
const tableFields = [
|
|
6
6
|
{ name: "secret", type: "TEXT", unique: true, primary: false },
|
|
@@ -107,29 +107,17 @@ class UserApiKeySqliteRepository {
|
|
|
107
107
|
stmt.run(id);
|
|
108
108
|
return true;
|
|
109
109
|
}
|
|
110
|
-
async paginate({ page = 1, limit = 5, orderBy = '',
|
|
110
|
+
async paginate({ page = 1, limit = 5, orderBy = '', order = false, search = '', filters = [] }) {
|
|
111
111
|
const offset = page > 1 ? (page - 1) * limit : 0;
|
|
112
112
|
let where = "";
|
|
113
113
|
if (search) {
|
|
114
114
|
where = ` WHERE name LIKE '%${search}%'`;
|
|
115
115
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
for (const filter of filters) {
|
|
120
|
-
if (['eq', '$eq'].includes(filter.operator)) {
|
|
121
|
-
whereFilters.push(` ${filter.field} = '${filter.value}' `);
|
|
122
|
-
}
|
|
123
|
-
if (['ne', '$ne'].includes(filter.operator)) {
|
|
124
|
-
whereFilters.push(` ${filter.field} != '${filter.value}' `);
|
|
125
|
-
}
|
|
126
|
-
if (['in', '$in'].includes(filter.operator)) {
|
|
127
|
-
whereFilters.push(` ${filter.field} LIKE '%${filter.value}%' `);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
where += whereFilters.join(" AND ");
|
|
131
|
-
}
|
|
116
|
+
where = SqlQueryFilter.applyFilters(where, filters);
|
|
117
|
+
const sort = SqlSort.applySort(orderBy, order);
|
|
118
|
+
console.log("where", where);
|
|
132
119
|
const rCount = this.db.prepare('SELECT COUNT(*) as count FROM user_api_keys' + where).get();
|
|
120
|
+
where += sort;
|
|
133
121
|
const userApiKeys = this.db.prepare('SELECT * FROM user_api_keys ' + where + ' LIMIT ? OFFSET ?').all([limit, offset]);
|
|
134
122
|
for (const userApiKey of userApiKeys) {
|
|
135
123
|
userApiKey.ipv4 = userApiKey.ipv4 != "" ? userApiKey.ipv4.split(',') : [];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import sqlite from "better-sqlite3";
|
|
2
2
|
import { randomUUID } from "node:crypto";
|
|
3
|
-
import { SqliteErrorToValidationError, SqliteTableBuilder, ValidationError } from "@drax/common-back";
|
|
3
|
+
import { SqliteErrorToValidationError, SqliteTableBuilder, SqlQueryFilter, SqlSort, ValidationError } from "@drax/common-back";
|
|
4
4
|
import RoleSqliteRepository from "./RoleSqliteRepository.js";
|
|
5
5
|
import TenantSqliteRepository from "./TenantSqliteRepository.js";
|
|
6
6
|
const tableFields = [
|
|
@@ -110,30 +110,17 @@ class UserSqliteRepository {
|
|
|
110
110
|
user.tenant = await this.findTenantById(user.tenant);
|
|
111
111
|
return user;
|
|
112
112
|
}
|
|
113
|
-
async paginate({ page = 1, limit = 5, orderBy = '',
|
|
113
|
+
async paginate({ page = 1, limit = 5, orderBy = '', order = false, search = '', filters = [] }) {
|
|
114
114
|
const offset = page > 1 ? (page - 1) * limit : 0;
|
|
115
115
|
let where = "";
|
|
116
116
|
if (search) {
|
|
117
117
|
where = ` WHERE (name LIKE '%${search}%' OR username LIKE '%${search}%') `;
|
|
118
118
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
for (const filter of filters) {
|
|
123
|
-
if (['eq', '$eq'].includes(filter.operator)) {
|
|
124
|
-
whereFilters.push(` ${filter.field} = '${filter.value}' `);
|
|
125
|
-
}
|
|
126
|
-
if (['ne', '$ne'].includes(filter.operator)) {
|
|
127
|
-
whereFilters.push(` ${filter.field} != '${filter.value}' `);
|
|
128
|
-
}
|
|
129
|
-
if (['in', '$in'].includes(filter.operator)) {
|
|
130
|
-
whereFilters.push(` ${filter.field} LIKE '%${filter.value}%' `);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
where += whereFilters.join(" AND ");
|
|
134
|
-
}
|
|
135
|
-
console.log("paginate where ", where, "search", search, "filters", filters, "whereFilters", whereFilters);
|
|
119
|
+
where = SqlQueryFilter.applyFilters(where, filters);
|
|
120
|
+
const sort = SqlSort.applySort(orderBy, order);
|
|
121
|
+
console.log("paginate where ", where, "search", search, "filters", filters);
|
|
136
122
|
const rCount = this.db.prepare('SELECT COUNT(*) as count FROM users' + where).get();
|
|
123
|
+
where += sort;
|
|
137
124
|
const users = this.db.prepare('SELECT * FROM users' + where + ' LIMIT ? OFFSET ?').all([limit, offset]);
|
|
138
125
|
for (const user of users) {
|
|
139
126
|
let role = await this.findRoleById(user.role);
|
|
@@ -104,10 +104,10 @@ async function RoleRoutes(fastify, options) {
|
|
|
104
104
|
const page = request.query.page;
|
|
105
105
|
const limit = request.query.limit;
|
|
106
106
|
const orderBy = request.query.orderBy;
|
|
107
|
-
const
|
|
107
|
+
const order = request.query.order;
|
|
108
108
|
const search = request.query.search;
|
|
109
109
|
const roleService = RoleServiceFactory();
|
|
110
|
-
let paginateResult = await roleService.paginate({ page, limit, search, orderBy,
|
|
110
|
+
let paginateResult = await roleService.paginate({ page, limit, search, orderBy, order });
|
|
111
111
|
return paginateResult;
|
|
112
112
|
}
|
|
113
113
|
catch (e) {
|
|
@@ -85,10 +85,10 @@ async function TenantRoutes(fastify, options) {
|
|
|
85
85
|
const page = request.query.page;
|
|
86
86
|
const limit = request.query.limit;
|
|
87
87
|
const orderBy = request.query.orderBy;
|
|
88
|
-
const
|
|
88
|
+
const order = request.query.order;
|
|
89
89
|
const search = request.query.search;
|
|
90
90
|
const tenantService = TenantServiceFactory();
|
|
91
|
-
let paginateResult = await tenantService.paginate({ page, limit, orderBy,
|
|
91
|
+
let paginateResult = await tenantService.paginate({ page, limit, orderBy, order, search });
|
|
92
92
|
return paginateResult;
|
|
93
93
|
}
|
|
94
94
|
catch (e) {
|
|
@@ -17,10 +17,10 @@ async function UserApiKeyRoutes(fastify, options) {
|
|
|
17
17
|
const page = request.query.page;
|
|
18
18
|
const limit = request.query.limit;
|
|
19
19
|
const orderBy = request.query.orderBy;
|
|
20
|
-
const
|
|
20
|
+
const order = request.query.order;
|
|
21
21
|
const search = request.query.search;
|
|
22
22
|
const userApiKeyService = UserApiKeyServiceFactory();
|
|
23
|
-
let paginateResult = await userApiKeyService.paginate({ page, limit, orderBy,
|
|
23
|
+
let paginateResult = await userApiKeyService.paginate({ page, limit, orderBy, order, search, filters });
|
|
24
24
|
return paginateResult;
|
|
25
25
|
}
|
|
26
26
|
catch (e) {
|
|
@@ -55,14 +55,14 @@ async function UserRoutes(fastify, options) {
|
|
|
55
55
|
const page = request.query.page;
|
|
56
56
|
const limit = request.query.limit;
|
|
57
57
|
const orderBy = request.query.orderBy;
|
|
58
|
-
const
|
|
58
|
+
const order = request.query.order;
|
|
59
59
|
const search = request.query.search;
|
|
60
60
|
const userService = UserServiceFactory();
|
|
61
61
|
const filters = [];
|
|
62
62
|
if (request.rbac.getAuthUser.tenantId) {
|
|
63
|
-
filters.push({ field: 'tenant', operator: '
|
|
63
|
+
filters.push({ field: 'tenant', operator: 'eq', value: request.rbac.getAuthUser.tenantId });
|
|
64
64
|
}
|
|
65
|
-
let paginateResult = await userService.paginate({ page, limit, orderBy,
|
|
65
|
+
let paginateResult = await userService.paginate({ page, limit, orderBy, order, search, filters });
|
|
66
66
|
for (let item of paginateResult.items) {
|
|
67
67
|
item.password = undefined;
|
|
68
68
|
delete item.password;
|
|
@@ -70,9 +70,9 @@ class RoleService {
|
|
|
70
70
|
const roles = await this._repository.fetchAll();
|
|
71
71
|
return roles;
|
|
72
72
|
}
|
|
73
|
-
async paginate({ page = 1, limit = 5, orderBy = '',
|
|
73
|
+
async paginate({ page = 1, limit = 5, orderBy = '', order = false, search = '', filters = [] }) {
|
|
74
74
|
try {
|
|
75
|
-
const pagination = await this._repository.paginate({ page, limit, orderBy,
|
|
75
|
+
const pagination = await this._repository.paginate({ page, limit, orderBy, order, search, filters });
|
|
76
76
|
return pagination;
|
|
77
77
|
}
|
|
78
78
|
catch (e) {
|
|
@@ -76,9 +76,9 @@ class TenantService {
|
|
|
76
76
|
throw e;
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
|
-
async paginate({ page = 1, limit = 5, orderBy = '',
|
|
79
|
+
async paginate({ page = 1, limit = 5, orderBy = '', order = false, search = '', filters = [] }) {
|
|
80
80
|
try {
|
|
81
|
-
const pagination = await this._repository.paginate({ page, limit, orderBy,
|
|
81
|
+
const pagination = await this._repository.paginate({ page, limit, orderBy, order, search, filters });
|
|
82
82
|
return pagination;
|
|
83
83
|
}
|
|
84
84
|
catch (e) {
|
|
@@ -76,9 +76,9 @@ class UserApiKeyService {
|
|
|
76
76
|
throw e;
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
|
-
async paginate({ page = 1, limit = 5, orderBy = '',
|
|
79
|
+
async paginate({ page = 1, limit = 5, orderBy = '', order = false, search = '', filters = [] }) {
|
|
80
80
|
try {
|
|
81
|
-
const pagination = await this._repository.paginate({ page, limit, orderBy,
|
|
81
|
+
const pagination = await this._repository.paginate({ page, limit, orderBy, order, search, filters });
|
|
82
82
|
return pagination;
|
|
83
83
|
}
|
|
84
84
|
catch (e) {
|
|
@@ -129,9 +129,9 @@ class UserService {
|
|
|
129
129
|
throw e;
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
|
-
async paginate({ page = 1, limit = 5, orderBy = '',
|
|
132
|
+
async paginate({ page = 1, limit = 5, orderBy = '', order = false, search = '', filters = [] }) {
|
|
133
133
|
try {
|
|
134
|
-
const pagination = await this._repository.paginate({ page, limit, orderBy,
|
|
134
|
+
const pagination = await this._repository.paginate({ page, limit, orderBy, order, search, filters });
|
|
135
135
|
return pagination;
|
|
136
136
|
}
|
|
137
137
|
catch (e) {
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "0.
|
|
6
|
+
"version": "0.3.0",
|
|
7
7
|
"description": "Identity module for user management, authentication and authorization.",
|
|
8
8
|
"main": "dist/index.js",
|
|
9
9
|
"types": "types/index.d.ts",
|
|
@@ -28,9 +28,9 @@
|
|
|
28
28
|
"author": "Cristian Incarnato & Drax Team",
|
|
29
29
|
"license": "ISC",
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@drax/common-back": "^0.
|
|
32
|
-
"@drax/common-share": "^0.
|
|
33
|
-
"@drax/identity-share": "^0.
|
|
31
|
+
"@drax/common-back": "^0.3.0",
|
|
32
|
+
"@drax/common-share": "^0.3.0",
|
|
33
|
+
"@drax/identity-share": "^0.3.0",
|
|
34
34
|
"bcryptjs": "^2.4.3",
|
|
35
35
|
"express-jwt": "^8.4.1",
|
|
36
36
|
"graphql": "^16.8.2",
|
|
@@ -61,5 +61,5 @@
|
|
|
61
61
|
"debug": "0"
|
|
62
62
|
}
|
|
63
63
|
},
|
|
64
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "5ec8cb15b649fb29c69fbb7f248346487e0e9be2"
|
|
65
65
|
}
|
|
@@ -62,7 +62,7 @@ export default {
|
|
|
62
62
|
throw new GraphQLError('error.server')
|
|
63
63
|
}
|
|
64
64
|
},
|
|
65
|
-
paginateRole: async (_, {options= {page:1, limit:5, orderBy:"",
|
|
65
|
+
paginateRole: async (_, {options= {page:1, limit:5, orderBy:"", order:false, search:"", filters: []} }, {rbac}) => {
|
|
66
66
|
try {
|
|
67
67
|
rbac.assertPermission(IdentityPermissions.ViewRole)
|
|
68
68
|
const roleService = RoleServiceFactory()
|
|
@@ -49,7 +49,7 @@ export default {
|
|
|
49
49
|
throw new GraphQLError('error.server')
|
|
50
50
|
}
|
|
51
51
|
},
|
|
52
|
-
paginateTenant: async (_, {options= {page:1, limit:5, orderBy:"",
|
|
52
|
+
paginateTenant: async (_, {options= {page:1, limit:5, orderBy:"", order:false, search:"", filters: []} }, {rbac}) => {
|
|
53
53
|
try {
|
|
54
54
|
rbac.assertPermission(IdentityPermissions.ViewTenant)
|
|
55
55
|
const tenantService = TenantServiceFactory()
|
|
@@ -8,7 +8,7 @@ import * as crypto from "node:crypto";
|
|
|
8
8
|
|
|
9
9
|
export default {
|
|
10
10
|
Query: {
|
|
11
|
-
paginateUserApiKey: async (_, {options= {page:1, limit:5, orderBy:"",
|
|
11
|
+
paginateUserApiKey: async (_, {options= {page:1, limit:5, orderBy:"", order:false, search:"", filters: []} }, {rbac, authUser}) => {
|
|
12
12
|
try {
|
|
13
13
|
rbac.assertAuthenticated()
|
|
14
14
|
|
|
@@ -45,7 +45,7 @@ export default {
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
},
|
|
48
|
-
paginateUser: async (_, { options= {page:1, limit:5, orderBy:"",
|
|
48
|
+
paginateUser: async (_, { options= {page:1, limit:5, orderBy:"", order:false, search:"", filters: []} }, {rbac}) => {
|
|
49
49
|
try {
|
|
50
50
|
rbac.assertPermission(IdentityPermissions.ViewUser)
|
|
51
51
|
let userService = UserServiceFactory()
|
|
@@ -55,7 +55,7 @@ export default {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
if (rbac.getAuthUser.tenantId) {
|
|
58
|
-
options.filters.push({field: 'tenant', operator: '
|
|
58
|
+
options.filters.push({field: 'tenant', operator: 'eq', value: rbac.getAuthUser.tenantId})
|
|
59
59
|
}
|
|
60
60
|
return await userService.paginate(options)
|
|
61
61
|
} catch (e) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {RoleModel} from "../../models/RoleModel.js";
|
|
2
2
|
import {IRoleRepository} from '../../interfaces/IRoleRepository'
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import {mongoose, MongooseQueryFilter, MongooseSort} from "@drax/common-back";
|
|
4
|
+
import {PaginateOptions, PaginateResult} from "mongoose";
|
|
5
5
|
import {DeleteResult} from "mongodb";
|
|
6
6
|
import {IDraxPaginateOptions, IDraxPaginateResult} from "@drax/common-share";
|
|
7
7
|
import {IRoleBase, IRole} from "@drax/identity-share";
|
|
@@ -44,7 +44,7 @@ class RoleMongoRepository implements IRoleRepository{
|
|
|
44
44
|
page= 1,
|
|
45
45
|
limit= 5,
|
|
46
46
|
orderBy= '',
|
|
47
|
-
|
|
47
|
+
order= false,
|
|
48
48
|
search= '',
|
|
49
49
|
filters= []} : IDraxPaginateOptions): Promise<IDraxPaginateResult<IRole>> {
|
|
50
50
|
const query = {}
|
|
@@ -55,7 +55,11 @@ class RoleMongoRepository implements IRoleRepository{
|
|
|
55
55
|
]
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
MongooseQueryFilter.applyFilters(query, filters)
|
|
59
|
+
|
|
60
|
+
const sort = MongooseSort.applySort(orderBy, order)
|
|
61
|
+
|
|
62
|
+
const options = {populate: ['childRoles'], page, limit, sort} as PaginateOptions
|
|
59
63
|
const roles: PaginateResult<IRole> = await RoleModel.paginate(query, options)
|
|
60
64
|
return {
|
|
61
65
|
page: page,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {TenantModel} from "../../models/TenantModel.js";
|
|
2
2
|
import {ITenantRepository} from '../../interfaces/ITenantRepository'
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import {mongoose, MongooseSort, MongooseQueryFilter} from "@drax/common-back";
|
|
4
|
+
import { PaginateOptions, PaginateResult} from "mongoose";
|
|
5
5
|
import {DeleteResult} from "mongodb";
|
|
6
6
|
import {IDraxPaginateOptions, IDraxPaginateResult} from "@drax/common-share";
|
|
7
7
|
import {ITenant, ITenantBase} from "@drax/identity-share";
|
|
@@ -43,7 +43,7 @@ class TenantMongoRepository implements ITenantRepository{
|
|
|
43
43
|
page= 1,
|
|
44
44
|
limit= 5,
|
|
45
45
|
orderBy= '',
|
|
46
|
-
|
|
46
|
+
order= false,
|
|
47
47
|
search= '',
|
|
48
48
|
filters= []} : IDraxPaginateOptions): Promise<IDraxPaginateResult<ITenant>> {
|
|
49
49
|
|
|
@@ -55,7 +55,11 @@ class TenantMongoRepository implements ITenantRepository{
|
|
|
55
55
|
]
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
MongooseQueryFilter.applyFilters(query, filters)
|
|
59
|
+
|
|
60
|
+
const sort = MongooseSort.applySort(orderBy, order)
|
|
61
|
+
|
|
62
|
+
const options = {page, limit, sort} as PaginateOptions
|
|
59
63
|
const tenants: PaginateResult<ITenant> = await TenantModel.paginate(query, options)
|
|
60
64
|
return {
|
|
61
65
|
page: page,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {UserApiKeyModel} from "../../models/UserApiKeyModel.js";
|
|
2
2
|
import {
|
|
3
3
|
mongoose,
|
|
4
|
-
MongooseErrorToValidationError,
|
|
4
|
+
MongooseErrorToValidationError, MongooseQueryFilter, MongooseSort,
|
|
5
5
|
MongoServerErrorToValidationError,
|
|
6
6
|
ValidationError
|
|
7
7
|
} from "@drax/common-back"
|
|
@@ -69,7 +69,7 @@ class UserMongoRepository implements IUserApiKeyRepository {
|
|
|
69
69
|
page = 1,
|
|
70
70
|
limit = 5,
|
|
71
71
|
orderBy = '',
|
|
72
|
-
|
|
72
|
+
order = false,
|
|
73
73
|
search = '',
|
|
74
74
|
filters = []
|
|
75
75
|
}: IDraxPaginateOptions): Promise<IDraxPaginateResult<IUserApiKey>> {
|
|
@@ -84,21 +84,11 @@ class UserMongoRepository implements IUserApiKeyRepository {
|
|
|
84
84
|
]
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
query[filter.field] = {$eq: filter.value}
|
|
91
|
-
}
|
|
92
|
-
if(['ne','$ne'].includes(filter.operator)){
|
|
93
|
-
query[filter.field] = {$ne: filter.value}
|
|
94
|
-
}
|
|
95
|
-
if(['in','$in'].includes(filter.operator)){
|
|
96
|
-
query[filter.field] = {$in: filter.value}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
87
|
+
MongooseQueryFilter.applyFilters(query, filters)
|
|
88
|
+
|
|
89
|
+
const sort = MongooseSort.applySort(orderBy, order)
|
|
100
90
|
|
|
101
|
-
const options = {populate: ['user', 'user.tenant', 'user.role'], page
|
|
91
|
+
const options = {populate: ['user', 'user.tenant', 'user.role'], page, limit, sort}
|
|
102
92
|
|
|
103
93
|
const userApiKeyPaginated: PaginateResult<IUserApiKey> = await UserApiKeyModel.paginate(query, options)
|
|
104
94
|
return {
|