@drax/dashboard-back 0.37.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.
Files changed (47) hide show
  1. package/dist/controllers/DashboardController.js +18 -0
  2. package/dist/factory/services/DashboardServiceFactory.js +15 -0
  3. package/dist/index.js +9 -0
  4. package/dist/interfaces/IDashboard.js +1 -0
  5. package/dist/interfaces/IDashboardRepository.js +1 -0
  6. package/dist/models/DashboardModel.js +65 -0
  7. package/dist/permissions/DashboardPermissions.js +10 -0
  8. package/dist/repository/DashboardRepository.js +12 -0
  9. package/dist/routes/DashboardRoutes.js +18 -0
  10. package/dist/schemas/DashboardSchema.js +39 -0
  11. package/dist/services/DashboardService.js +8 -0
  12. package/package.json +43 -0
  13. package/src/controllers/DashboardController.ts +27 -0
  14. package/src/factory/services/DashboardServiceFactory.ts +23 -0
  15. package/src/index.ts +25 -0
  16. package/src/interfaces/IDashboard.ts +75 -0
  17. package/src/interfaces/IDashboardRepository.ts +11 -0
  18. package/src/models/DashboardModel.ts +79 -0
  19. package/src/permissions/DashboardPermissions.ts +14 -0
  20. package/src/repository/DashboardRepository.ts +21 -0
  21. package/src/routes/DashboardRoutes.ts +30 -0
  22. package/src/schemas/DashboardSchema.ts +48 -0
  23. package/src/services/DashboardService.ts +16 -0
  24. package/tsconfig.json +16 -0
  25. package/tsconfig.tsbuildinfo +1 -0
  26. package/types/controllers/DashboardController.d.ts +8 -0
  27. package/types/controllers/DashboardController.d.ts.map +1 -0
  28. package/types/factory/services/DashboardServiceFactory.d.ts +8 -0
  29. package/types/factory/services/DashboardServiceFactory.d.ts.map +1 -0
  30. package/types/index.d.ts +13 -0
  31. package/types/index.d.ts.map +1 -0
  32. package/types/interfaces/IDashboard.d.ts +71 -0
  33. package/types/interfaces/IDashboard.d.ts.map +1 -0
  34. package/types/interfaces/IDashboardRepository.d.ts +6 -0
  35. package/types/interfaces/IDashboardRepository.d.ts.map +1 -0
  36. package/types/models/DashboardModel.d.ts +15 -0
  37. package/types/models/DashboardModel.d.ts.map +1 -0
  38. package/types/permissions/DashboardPermissions.d.ts +10 -0
  39. package/types/permissions/DashboardPermissions.d.ts.map +1 -0
  40. package/types/repository/DashboardRepository.d.ts +9 -0
  41. package/types/repository/DashboardRepository.d.ts.map +1 -0
  42. package/types/routes/DashboardRoutes.d.ts +4 -0
  43. package/types/routes/DashboardRoutes.d.ts.map +1 -0
  44. package/types/schemas/DashboardSchema.d.ts +380 -0
  45. package/types/schemas/DashboardSchema.d.ts.map +1 -0
  46. package/types/services/DashboardService.d.ts +10 -0
  47. package/types/services/DashboardService.d.ts.map +1 -0
@@ -0,0 +1,18 @@
1
+ import DashboardServiceFactory from "../factory/services/DashboardServiceFactory.js";
2
+ import { AbstractFastifyController } from "@drax/crud-back";
3
+ import DashboardPermissions from "../permissions/DashboardPermissions.js";
4
+ class DashboardController extends AbstractFastifyController {
5
+ constructor() {
6
+ super(DashboardServiceFactory.instance, DashboardPermissions);
7
+ this.tenantField = "tenant";
8
+ this.userField = "user";
9
+ this.tenantFilter = false;
10
+ this.userFilter = false;
11
+ this.tenantSetter = false;
12
+ this.userSetter = false;
13
+ this.tenantAssert = false;
14
+ this.userAssert = false;
15
+ }
16
+ }
17
+ export default DashboardController;
18
+ export { DashboardController };
@@ -0,0 +1,15 @@
1
+ import DashboardRepository from '../../repository/DashboardRepository.js';
2
+ import { DashboardService } from '../../services/DashboardService.js';
3
+ import { DashboardBaseSchema } from "../../schemas/DashboardSchema.js";
4
+ class DashboardServiceFactory {
5
+ static get instance() {
6
+ if (!DashboardServiceFactory.service) {
7
+ const repository = new DashboardRepository();
8
+ const schema = DashboardBaseSchema;
9
+ DashboardServiceFactory.service = new DashboardService(repository, schema);
10
+ }
11
+ return DashboardServiceFactory.service;
12
+ }
13
+ }
14
+ export default DashboardServiceFactory;
15
+ export { DashboardServiceFactory };
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ import DashboardPermissions from './permissions/DashboardPermissions.js';
2
+ import DashboardSchema from './schemas/DashboardSchema.js';
3
+ import DashboardModel from './models/DashboardModel.js';
4
+ import DashboardRepository from './repository/DashboardRepository.js';
5
+ import DashboardService from './services/DashboardService.js';
6
+ import DashboardServiceFactory from './factory/services/DashboardServiceFactory.js';
7
+ import DashboardController from './controllers/DashboardController.js';
8
+ import DashboardRoutes from './routes/DashboardRoutes.js';
9
+ export { DashboardPermissions, DashboardSchema, DashboardModel, DashboardRepository, DashboardService, DashboardServiceFactory, DashboardController, DashboardRoutes };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,65 @@
1
+ import { mongoose } from '@drax/common-back';
2
+ import uniqueValidator from 'mongoose-unique-validator';
3
+ import mongoosePaginate from 'mongoose-paginate-v2';
4
+ const DashboardSchema = new mongoose.Schema({
5
+ identifier: { type: String, required: true, index: true, unique: true },
6
+ title: { type: String, required: true, index: true, unique: true },
7
+ cards: [{
8
+ title: { type: String, required: true, index: false, unique: false },
9
+ entity: { type: String, required: true, index: false, unique: false },
10
+ type: { type: String, enum: ['paginate', 'groupBy'], required: true, index: false, unique: false },
11
+ filters: [{
12
+ field: { type: String, required: true, index: false, unique: false },
13
+ operator: { type: String, required: true, index: false, unique: false },
14
+ value: { type: String, required: true, index: false, unique: false }
15
+ }],
16
+ layout: {
17
+ cols: { type: Number, required: true, index: false, unique: false },
18
+ sm: { type: Number, required: true, index: false, unique: false },
19
+ md: { type: Number, required: true, index: false, unique: false },
20
+ lg: { type: Number, required: true, index: false, unique: false },
21
+ height: { type: Number, required: true, index: false, unique: false },
22
+ cardVariant: {
23
+ type: String,
24
+ enum: ['text', 'flat', 'elevated', 'tonal', 'outlined', 'plain'],
25
+ required: true,
26
+ index: false,
27
+ unique: false
28
+ }
29
+ },
30
+ groupBy: {
31
+ fields: [{ type: String, required: true, index: false, unique: false }],
32
+ dateFormat: {
33
+ type: String,
34
+ enum: ['year', 'month', 'day', 'hour', 'minute', 'second'],
35
+ required: false,
36
+ index: false,
37
+ unique: false
38
+ },
39
+ render: {
40
+ type: String,
41
+ enum: ['table', 'gallery', 'pie', 'bars'],
42
+ required: false,
43
+ index: false,
44
+ unique: false
45
+ }
46
+ },
47
+ paginate: {
48
+ columns: [{ type: String, required: true, index: false, unique: false }],
49
+ orderBy: { type: String, required: false, index: false, unique: false },
50
+ order: { type: String, enum: ['asc', 'desc', null], required: false, index: false, unique: false }
51
+ }
52
+ }]
53
+ }, { timestamps: true });
54
+ DashboardSchema.plugin(uniqueValidator, { message: 'validation.unique' });
55
+ DashboardSchema.plugin(mongoosePaginate);
56
+ DashboardSchema.virtual("id").get(function () {
57
+ return this._id.toString();
58
+ });
59
+ DashboardSchema.set('toJSON', { getters: true, virtuals: true });
60
+ DashboardSchema.set('toObject', { getters: true, virtuals: true });
61
+ const MODEL_NAME = 'Dashboard';
62
+ const COLLECTION_NAME = 'Dashboard';
63
+ const DashboardModel = mongoose.model(MODEL_NAME, DashboardSchema, COLLECTION_NAME);
64
+ export { DashboardSchema, DashboardModel };
65
+ export default DashboardModel;
@@ -0,0 +1,10 @@
1
+ var DashboardPermissions;
2
+ (function (DashboardPermissions) {
3
+ DashboardPermissions["Create"] = "dashboard:create";
4
+ DashboardPermissions["Update"] = "dashboard:update";
5
+ DashboardPermissions["Delete"] = "dashboard:delete";
6
+ DashboardPermissions["View"] = "dashboard:view";
7
+ DashboardPermissions["Manage"] = "dashboard:manage";
8
+ })(DashboardPermissions || (DashboardPermissions = {}));
9
+ export { DashboardPermissions };
10
+ export default DashboardPermissions;
@@ -0,0 +1,12 @@
1
+ import { AbstractMongoRepository } from "@drax/crud-back";
2
+ import { DashboardModel } from "../models/DashboardModel.js";
3
+ class DashboardMongoRepository extends AbstractMongoRepository {
4
+ constructor() {
5
+ super();
6
+ this._model = DashboardModel;
7
+ this._searchFields = ['identifier', 'title'];
8
+ this._populateFields = [];
9
+ }
10
+ }
11
+ export default DashboardMongoRepository;
12
+ export { DashboardMongoRepository };
@@ -0,0 +1,18 @@
1
+ import DashboardController from "../controllers/DashboardController.js";
2
+ import { CrudSchemaBuilder } from "@drax/crud-back";
3
+ import { DashboardSchema, DashboardBaseSchema } from '../schemas/DashboardSchema.js';
4
+ async function DashboardFastifyRoutes(fastify, options) {
5
+ const controller = new DashboardController();
6
+ const schemas = new CrudSchemaBuilder(DashboardSchema, DashboardBaseSchema, DashboardBaseSchema, 'Dashboard', 'openApi3', ['dashboard']);
7
+ fastify.get('/api/dashboard', { schema: schemas.paginateSchema }, (req, rep) => controller.paginate(req, rep));
8
+ fastify.get('/api/dashboard/find', { schema: schemas.findSchema }, (req, rep) => controller.find(req, rep));
9
+ fastify.get('/api/dashboard/search', { schema: schemas.searchSchema }, (req, rep) => controller.search(req, rep));
10
+ fastify.get('/api/dashboard/:id', { schema: schemas.findByIdSchema }, (req, rep) => controller.findById(req, rep));
11
+ fastify.get('/api/dashboard/find-one', { schema: schemas.findOneSchema }, (req, rep) => controller.findOne(req, rep));
12
+ fastify.get('/api/dashboard/group-by', { schema: schemas.groupBySchema }, (req, rep) => controller.groupBy(req, rep));
13
+ fastify.post('/api/dashboard', { schema: schemas.createSchema }, (req, rep) => controller.create(req, rep));
14
+ fastify.put('/api/dashboard/:id', { schema: schemas.updateSchema }, (req, rep) => controller.update(req, rep));
15
+ fastify.delete('/api/dashboard/:id', { schema: schemas.deleteSchema }, (req, rep) => controller.delete(req, rep));
16
+ }
17
+ export default DashboardFastifyRoutes;
18
+ export { DashboardFastifyRoutes };
@@ -0,0 +1,39 @@
1
+ import { z } from 'zod';
2
+ const DashboardBaseSchema = z.object({
3
+ identifier: z.string().min(1, 'validation.required'),
4
+ title: z.string().min(1, 'validation.required'),
5
+ cards: z.array(z.object({
6
+ entity: z.string().min(1, 'validation.required'),
7
+ type: z.enum(['paginate', 'groupBy']),
8
+ title: z.string().min(1, 'validation.required'),
9
+ filters: z.array(z.object({
10
+ field: z.string().min(1, 'validation.required'),
11
+ operator: z.string().min(1, 'validation.required'),
12
+ value: z.string().min(1, 'validation.required')
13
+ })).optional(),
14
+ layout: z.object({
15
+ cols: z.number().min(0, 'validation.required').default(12),
16
+ sm: z.number().min(0, 'validation.required').default(12),
17
+ md: z.number().min(0, 'validation.required').default(12),
18
+ lg: z.number().min(0, 'validation.required').default(12),
19
+ height: z.number().min(0, 'validation.required').default(100),
20
+ cardVariant: z.enum(['text', 'flat', 'elevated', 'tonal', 'outlined', 'plain']).default('elevated')
21
+ }),
22
+ groupBy: z.object({
23
+ fields: z.array(z.string()),
24
+ dateFormat: z.enum(['year', 'month', 'day', 'hour', 'minute', 'second']).optional().default('day'),
25
+ render: z.enum(['table', 'gallery', 'pie', 'bars']).optional().default('table')
26
+ }),
27
+ paginate: z.object({
28
+ columns: z.array(z.string()).default([]),
29
+ orderBy: z.string().optional().nullable(),
30
+ order: z.enum(['asc', 'desc']).optional().nullable()
31
+ })
32
+ })).optional()
33
+ });
34
+ const DashboardSchema = DashboardBaseSchema
35
+ .extend({
36
+ _id: z.string(),
37
+ });
38
+ export default DashboardSchema;
39
+ export { DashboardSchema, DashboardBaseSchema };
@@ -0,0 +1,8 @@
1
+ import { AbstractService } from "@drax/crud-back";
2
+ class DashboardService extends AbstractService {
3
+ constructor(DashboardRepository, schema) {
4
+ super(DashboardRepository, schema);
5
+ }
6
+ }
7
+ export default DashboardService;
8
+ export { DashboardService };
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@drax/dashboard-back",
3
+ "publishConfig": {
4
+ "access": "public"
5
+ },
6
+ "version": "0.37.0",
7
+ "description": "Dahsboard backend",
8
+ "main": "dist/index.js",
9
+ "types": "types/index.d.ts",
10
+ "type": "module",
11
+ "scripts": {
12
+ "prepublish": "tsc && npm run copygql",
13
+ "tscrun": "tsc",
14
+ "clean": "rm -rf dist",
15
+ "copygql": "copyfiles -u 1 ./**/*.graphql dist/",
16
+ "tsc": "tsc -b tsconfig.json",
17
+ "test": "node --import tsx --test test/**/*",
18
+ "testService": "node --import tsx --test test/services/*.ts",
19
+ "testExports": "node --import tsx --test test/exports/*.ts",
20
+ "testWorkers": "node --import tsx --test test/workers/*.ts"
21
+ },
22
+ "author": "Cristian Incarnato & Drax Team",
23
+ "license": "ISC",
24
+ "dependencies": {
25
+ "@drax/crud-back": "^0.37.0",
26
+ "@drax/crud-share": "^0.37.0",
27
+ "mongoose": "^8.6.3",
28
+ "mongoose-paginate-v2": "^1.8.3"
29
+ },
30
+ "peerDependencies": {
31
+ "dayjs": "^1.11.13",
32
+ "mongoose-paginate-v2": "^1.8.3"
33
+ },
34
+ "devDependencies": {
35
+ "@types/node": "^20.12.10",
36
+ "copyfiles": "^2.4.1",
37
+ "mongoose-paginate-v2": "^1.8.3",
38
+ "ts-node": "^10.9.2",
39
+ "tsc-alias": "^1.8.10",
40
+ "typescript": "^5.6.2"
41
+ },
42
+ "gitHead": "0bca48d4b686fd9536a78d84f5befe6801238000"
43
+ }
@@ -0,0 +1,27 @@
1
+
2
+ import DashboardServiceFactory from "../factory/services/DashboardServiceFactory.js";
3
+ import {AbstractFastifyController} from "@drax/crud-back";
4
+ import DashboardPermissions from "../permissions/DashboardPermissions.js";
5
+ import type {IDashboard, IDashboardBase} from "../interfaces/IDashboard";
6
+
7
+ class DashboardController extends AbstractFastifyController<IDashboard, IDashboardBase, IDashboardBase> {
8
+
9
+ constructor() {
10
+ super(DashboardServiceFactory.instance, DashboardPermissions)
11
+ this.tenantField = "tenant";
12
+ this.userField = "user";
13
+ this.tenantFilter = false;
14
+ this.userFilter = false;
15
+ this.tenantSetter = false;
16
+ this.userSetter = false;
17
+ this.tenantAssert = false;
18
+ this.userAssert = false;
19
+ }
20
+
21
+ }
22
+
23
+ export default DashboardController;
24
+ export {
25
+ DashboardController
26
+ }
27
+
@@ -0,0 +1,23 @@
1
+
2
+ import DashboardRepository from '../../repository/DashboardRepository.js'
3
+ import {DashboardService} from '../../services/DashboardService.js'
4
+ import {DashboardBaseSchema} from "../../schemas/DashboardSchema.js";
5
+
6
+ class DashboardServiceFactory {
7
+ private static service: DashboardService;
8
+
9
+ public static get instance(): DashboardService {
10
+ if (!DashboardServiceFactory.service) {
11
+ const repository = new DashboardRepository();
12
+ const schema = DashboardBaseSchema;
13
+ DashboardServiceFactory.service = new DashboardService(repository, schema);
14
+ }
15
+ return DashboardServiceFactory.service;
16
+ }
17
+ }
18
+
19
+ export default DashboardServiceFactory
20
+ export {
21
+ DashboardServiceFactory
22
+ }
23
+
package/src/index.ts ADDED
@@ -0,0 +1,25 @@
1
+ import DashboardPermissions from './permissions/DashboardPermissions.js'
2
+ import DashboardSchema from './schemas/DashboardSchema.js'
3
+ import DashboardModel from './models/DashboardModel.js'
4
+ import DashboardRepository from './repository/DashboardRepository.js'
5
+ import DashboardService from './services/DashboardService.js'
6
+ import DashboardServiceFactory from './factory/services/DashboardServiceFactory.js'
7
+ import DashboardController from './controllers/DashboardController.js'
8
+ import DashboardRoutes from './routes/DashboardRoutes.js'
9
+ import type {IDashboard, IDashboardBase} from './interfaces/IDashboard'
10
+ import type {IDashboardRepository} from './interfaces/IDashboardRepository'
11
+
12
+ export type{
13
+ IDashboard, IDashboardBase,IDashboardRepository
14
+ }
15
+
16
+ export {
17
+ DashboardPermissions,
18
+ DashboardSchema,
19
+ DashboardModel,
20
+ DashboardRepository,
21
+ DashboardService,
22
+ DashboardServiceFactory,
23
+ DashboardController,
24
+ DashboardRoutes
25
+ }
@@ -0,0 +1,75 @@
1
+ interface IDashboardBase {
2
+ identifier: string
3
+ title: string
4
+ cards?: Array<{
5
+ entity: string
6
+ type: string
7
+ title: string
8
+ filters?: Array<{
9
+ field: string
10
+ operator: string
11
+ value: string
12
+ }>
13
+ layout?: {
14
+ cols: number
15
+ sm: number
16
+ md: number
17
+ lg: number
18
+ height: number
19
+ cardVariant: string
20
+ }
21
+ groupBy?: {
22
+ fields: Array<string>
23
+ dateFormat?: string
24
+ render?: string
25
+ }
26
+ paginate?: {
27
+ columns: Array<string>
28
+ orderBy?: string
29
+ order?: string
30
+ }
31
+ }>
32
+ createdAt?: Date
33
+ updatedAt?: Date
34
+ }
35
+
36
+ interface IDashboard {
37
+ _id: string
38
+ identifier: string
39
+ title: string
40
+ cards?: Array<{
41
+ entity: string
42
+ type: string
43
+ title: string
44
+ filters?: Array<{
45
+ field: string
46
+ operator: string
47
+ value: string
48
+ }>
49
+ layout?: {
50
+ cols: number
51
+ sm: number
52
+ md: number
53
+ lg: number
54
+ height: number
55
+ cardVariant: string
56
+ }
57
+ groupBy?: {
58
+ fields: Array<string>
59
+ dateFormat?: string
60
+ render?: string
61
+ }
62
+ paginate?: {
63
+ columns: Array<string>
64
+ orderBy?: string
65
+ order?: string
66
+ }
67
+ }>
68
+ createdAt?: Date
69
+ updatedAt?: Date
70
+ }
71
+
72
+ export type {
73
+ IDashboardBase,
74
+ IDashboard
75
+ }
@@ -0,0 +1,11 @@
1
+
2
+ import type {IDashboard, IDashboardBase} from './IDashboard'
3
+ import {IDraxCrudRepository} from "@drax/crud-share";
4
+
5
+ interface IDashboardRepository extends IDraxCrudRepository<IDashboard, IDashboardBase, IDashboardBase>{
6
+
7
+ }
8
+
9
+ export {IDashboardRepository}
10
+
11
+
@@ -0,0 +1,79 @@
1
+ import {mongoose} from '@drax/common-back';
2
+ import {PaginateModel} from "mongoose";
3
+ import uniqueValidator from 'mongoose-unique-validator';
4
+ import mongoosePaginate from 'mongoose-paginate-v2'
5
+ import type {IDashboard} from '../interfaces/IDashboard'
6
+
7
+ const DashboardSchema = new mongoose.Schema<IDashboard>({
8
+ identifier: {type: String, required: true, index: true, unique: true},
9
+ title: {type: String, required: true, index: true, unique: true},
10
+ cards: [{
11
+ title: {type: String, required: true, index: false, unique: false},
12
+ entity: {type: String, required: true, index: false, unique: false},
13
+ type: {type: String, enum: ['paginate', 'groupBy'], required: true, index: false, unique: false},
14
+ filters: [{
15
+ field: {type: String, required: true, index: false, unique: false},
16
+ operator: {type: String, required: true, index: false, unique: false},
17
+ value: {type: String, required: true, index: false, unique: false}
18
+ }],
19
+ layout: {
20
+ cols: {type: Number, required: true, index: false, unique: false},
21
+ sm: {type: Number, required: true, index: false, unique: false},
22
+ md: {type: Number, required: true, index: false, unique: false},
23
+ lg: {type: Number, required: true, index: false, unique: false},
24
+ height: {type: Number, required: true, index: false, unique: false},
25
+ cardVariant: {
26
+ type: String,
27
+ enum: ['text', 'flat', 'elevated', 'tonal', 'outlined', 'plain'],
28
+ required: true,
29
+ index: false,
30
+ unique: false
31
+ }
32
+ },
33
+ groupBy: {
34
+ fields: [{type: String, required: true, index: false, unique: false}],
35
+ dateFormat: {
36
+ type: String,
37
+ enum: ['year', 'month', 'day', 'hour', 'minute', 'second'],
38
+ required: false,
39
+ index: false,
40
+ unique: false
41
+ },
42
+ render: {
43
+ type: String,
44
+ enum: ['table', 'gallery', 'pie', 'bars'],
45
+ required: false,
46
+ index: false,
47
+ unique: false
48
+ }
49
+ },
50
+ paginate: {
51
+ columns: [{type: String, required: true, index: false, unique: false}],
52
+ orderBy: {type: String, required: false, index: false, unique: false},
53
+ order: {type: String, enum: ['asc', 'desc', null], required: false, index: false, unique: false}
54
+ }
55
+ }]
56
+ }, {timestamps: true});
57
+
58
+ DashboardSchema.plugin(uniqueValidator, {message: 'validation.unique'});
59
+ DashboardSchema.plugin(mongoosePaginate);
60
+
61
+ DashboardSchema.virtual("id").get(function () {
62
+ return this._id.toString();
63
+ });
64
+
65
+
66
+ DashboardSchema.set('toJSON', {getters: true, virtuals: true});
67
+
68
+ DashboardSchema.set('toObject', {getters: true, virtuals: true});
69
+
70
+ const MODEL_NAME = 'Dashboard';
71
+ const COLLECTION_NAME = 'Dashboard';
72
+ const DashboardModel = mongoose.model<IDashboard, PaginateModel<IDashboard>>(MODEL_NAME, DashboardSchema, COLLECTION_NAME);
73
+
74
+ export {
75
+ DashboardSchema,
76
+ DashboardModel
77
+ }
78
+
79
+ export default DashboardModel
@@ -0,0 +1,14 @@
1
+
2
+ enum DashboardPermissions {
3
+
4
+ Create = "dashboard:create",
5
+ Update = "dashboard:update",
6
+ Delete = "dashboard:delete",
7
+ View = "dashboard:view",
8
+ Manage = "dashboard:manage"
9
+
10
+ }
11
+
12
+ export { DashboardPermissions };
13
+ export default DashboardPermissions;
14
+
@@ -0,0 +1,21 @@
1
+
2
+ import {AbstractMongoRepository} from "@drax/crud-back";
3
+ import {DashboardModel} from "../models/DashboardModel.js";
4
+ import type {IDashboardRepository} from '../interfaces/IDashboardRepository'
5
+ import type {IDashboard, IDashboardBase} from "../interfaces/IDashboard";
6
+
7
+
8
+ class DashboardMongoRepository extends AbstractMongoRepository<IDashboard, IDashboardBase, IDashboardBase> implements IDashboardRepository {
9
+
10
+ constructor() {
11
+ super();
12
+ this._model = DashboardModel;
13
+ this._searchFields = ['identifier', 'title'];
14
+ this._populateFields = [];
15
+ }
16
+
17
+ }
18
+
19
+ export default DashboardMongoRepository
20
+ export {DashboardMongoRepository}
21
+
@@ -0,0 +1,30 @@
1
+
2
+ import DashboardController from "../controllers/DashboardController.js";
3
+ import {CrudSchemaBuilder} from "@drax/crud-back";
4
+ import {DashboardSchema, DashboardBaseSchema} from '../schemas/DashboardSchema.js'
5
+
6
+ async function DashboardFastifyRoutes(fastify, options) {
7
+
8
+ const controller: DashboardController = new DashboardController()
9
+ const schemas = new CrudSchemaBuilder(DashboardSchema, DashboardBaseSchema,DashboardBaseSchema, 'Dashboard', 'openApi3', ['dashboard']);
10
+
11
+ fastify.get('/api/dashboard', {schema: schemas.paginateSchema}, (req,rep) => controller.paginate(req,rep))
12
+
13
+ fastify.get('/api/dashboard/find', {schema: schemas.findSchema}, (req,rep) => controller.find(req,rep))
14
+ fastify.get('/api/dashboard/search', {schema: schemas.searchSchema}, (req,rep) => controller.search(req,rep))
15
+
16
+ fastify.get('/api/dashboard/:id', {schema: schemas.findByIdSchema}, (req,rep) => controller.findById(req,rep))
17
+ fastify.get('/api/dashboard/find-one', {schema: schemas.findOneSchema}, (req,rep) => controller.findOne(req,rep))
18
+
19
+ fastify.get('/api/dashboard/group-by', {schema: schemas.groupBySchema}, (req,rep) => controller.groupBy(req,rep))
20
+
21
+ fastify.post('/api/dashboard', {schema: schemas.createSchema}, (req,rep) =>controller.create(req,rep))
22
+
23
+ fastify.put('/api/dashboard/:id', {schema: schemas.updateSchema}, (req,rep) =>controller.update(req,rep))
24
+
25
+ fastify.delete('/api/dashboard/:id', {schema: schemas.deleteSchema}, (req,rep) =>controller.delete(req,rep))
26
+
27
+ }
28
+
29
+ export default DashboardFastifyRoutes;
30
+ export {DashboardFastifyRoutes}
@@ -0,0 +1,48 @@
1
+ import {z} from 'zod';
2
+
3
+
4
+ const DashboardBaseSchema = z.object({
5
+ identifier: z.string().min(1, 'validation.required'),
6
+ title: z.string().min(1, 'validation.required'),
7
+ cards: z.array(
8
+ z.object({
9
+ entity: z.string().min(1, 'validation.required'),
10
+ type: z.enum(['paginate', 'groupBy']),
11
+ title: z.string().min(1, 'validation.required'),
12
+ filters: z.array(
13
+ z.object({
14
+ field: z.string().min(1, 'validation.required'),
15
+ operator: z.string().min(1, 'validation.required'),
16
+ value: z.string().min(1, 'validation.required')
17
+ })
18
+ ).optional(),
19
+ layout: z.object({
20
+ cols: z.number().min(0, 'validation.required').default(12),
21
+ sm: z.number().min(0, 'validation.required').default(12),
22
+ md: z.number().min(0, 'validation.required').default(12),
23
+ lg: z.number().min(0, 'validation.required').default(12),
24
+ height: z.number().min(0, 'validation.required').default(100),
25
+ cardVariant: z.enum(['text', 'flat', 'elevated', 'tonal', 'outlined', 'plain']).default('elevated')
26
+ }),
27
+ groupBy: z.object({
28
+ fields: z.array(z.string()),
29
+ dateFormat: z.enum(['year', 'month', 'day', 'hour', 'minute', 'second']).optional().default('day'),
30
+ render: z.enum(['table', 'gallery', 'pie', 'bars']).optional().default('table')
31
+ }),
32
+ paginate: z.object({
33
+ columns: z.array(z.string()).default([]),
34
+ orderBy: z.string().optional().nullable(),
35
+ order: z.enum(['asc', 'desc']).optional().nullable()
36
+ })
37
+ })
38
+ ).optional()
39
+ });
40
+
41
+ const DashboardSchema = DashboardBaseSchema
42
+ .extend({
43
+ _id: z.string(),
44
+
45
+ })
46
+
47
+ export default DashboardSchema;
48
+ export {DashboardSchema, DashboardBaseSchema}
@@ -0,0 +1,16 @@
1
+
2
+ import type{IDashboardRepository} from "../interfaces/IDashboardRepository";
3
+ import type {IDashboardBase, IDashboard} from "../interfaces/IDashboard";
4
+ import {AbstractService} from "@drax/crud-back";
5
+ import type {ZodObject, ZodRawShape} from "zod";
6
+
7
+ class DashboardService extends AbstractService<IDashboard, IDashboardBase, IDashboardBase> {
8
+
9
+ constructor(DashboardRepository: IDashboardRepository, schema?: ZodObject<ZodRawShape>) {
10
+ super(DashboardRepository, schema);
11
+ }
12
+
13
+ }
14
+
15
+ export default DashboardService
16
+ export {DashboardService}
package/tsconfig.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "extends": "../../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "rootDir": "src",
5
+ "outDir": "dist",
6
+ "declarationDir": "types"
7
+ },
8
+ "exclude": ["test", "types","dist","node_modules"],
9
+ "ts-node": {
10
+ "esm": true
11
+ },
12
+ "tsc-alias": {
13
+ "resolveFullPaths": true,
14
+ "verbose": false
15
+ }
16
+ }