identity-admin 1.5.0 → 1.7.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 (99) hide show
  1. package/README.md +126 -126
  2. package/lib/Dashboard.d.ts +14 -14
  3. package/lib/Dashboard.js +95 -88
  4. package/lib/container/helpers/HelperInversify.d.ts +6 -6
  5. package/lib/container/helpers/HelperInversify.js +10 -10
  6. package/lib/container/helpers/HelperTypes.d.ts +5 -5
  7. package/lib/container/helpers/HelperTypes.js +7 -7
  8. package/lib/container/index.d.ts +1 -1
  9. package/lib/container/index.js +14 -14
  10. package/lib/container/repositories/RepositoryInversify.d.ts +4 -4
  11. package/lib/container/repositories/RepositoryInversify.js +13 -13
  12. package/lib/container/repositories/RepositoryTypes.d.ts +4 -4
  13. package/lib/container/repositories/RepositoryTypes.js +6 -6
  14. package/lib/container/types.d.ts +8 -8
  15. package/lib/container/types.js +9 -9
  16. package/lib/controllers/ActionController.d.ts +8 -8
  17. package/lib/controllers/ActionController.js +79 -79
  18. package/lib/controllers/DashboardController.d.ts +37 -36
  19. package/lib/controllers/DashboardController.js +388 -337
  20. package/lib/controllers/ResourceController.d.ts +11 -9
  21. package/lib/controllers/ResourceController.js +109 -104
  22. package/lib/helpers/ActionsGenerator.d.ts +9 -9
  23. package/lib/helpers/ActionsGenerator.js +101 -77
  24. package/lib/helpers/FiltersHelper.d.ts +7 -0
  25. package/lib/helpers/FiltersHelper.js +71 -0
  26. package/lib/helpers/LocalesHelper.d.ts +4 -4
  27. package/lib/helpers/LocalesHelper.js +73 -73
  28. package/lib/helpers/LocalizedStringHelper.d.ts +9 -0
  29. package/lib/helpers/LocalizedStringHelper.js +57 -0
  30. package/lib/helpers/ResourceGenerator.d.ts +4 -4
  31. package/lib/helpers/ResourceGenerator.js +110 -68
  32. package/lib/helpers/ResourceHelper.d.ts +23 -22
  33. package/lib/helpers/ResourceHelper.js +305 -286
  34. package/lib/helpers/SchemaGenerator.d.ts +5 -5
  35. package/lib/helpers/SchemaGenerator.js +92 -87
  36. package/lib/helpers/SchemaHelper.d.ts +5 -5
  37. package/lib/helpers/SchemaHelper.js +21 -21
  38. package/lib/locales/ar.json +1 -0
  39. package/lib/locales/en.json +50 -10
  40. package/lib/middlewares/isAuth.d.ts +13 -13
  41. package/lib/middlewares/isAuth.js +43 -43
  42. package/lib/models/ModelNames.d.ts +4 -4
  43. package/lib/models/ModelNames.js +7 -7
  44. package/lib/models/request-log/IRequestLog.d.ts +22 -22
  45. package/lib/models/request-log/IRequestLog.js +2 -2
  46. package/lib/models/request-log/RequestLog.d.ts +3 -3
  47. package/lib/models/request-log/RequestLog.js +51 -51
  48. package/lib/repositories/DashboardRepository.d.ts +5 -5
  49. package/lib/repositories/DashboardRepository.js +12 -12
  50. package/lib/repositories/Repository.d.ts +68 -68
  51. package/lib/repositories/Repository.js +212 -212
  52. package/lib/repositories/RequestLogRepository.d.ts +10 -10
  53. package/lib/repositories/RequestLogRepository.js +54 -54
  54. package/lib/repositories/SaveResult.d.ts +14 -14
  55. package/lib/repositories/SaveResult.js +18 -18
  56. package/lib/router/index.d.ts +8 -8
  57. package/lib/router/index.js +97 -97
  58. package/lib/types/DashbordConfig.d.ts +21 -19
  59. package/lib/types/DashbordConfig.js +2 -2
  60. package/lib/types/IConfigurationFile.d.ts +5 -0
  61. package/lib/types/IConfigurationFile.js +2 -0
  62. package/lib/types/IResourceFile.d.ts +182 -131
  63. package/lib/types/IResourceFile.js +2 -2
  64. package/lib/types/helpers.d.ts +32 -15
  65. package/lib/types/helpers.js +39 -21
  66. package/lib/utils/ResourceUtils.d.ts +2 -2
  67. package/lib/utils/ResourceUtils.js +7 -7
  68. package/lib/utils/ResponseUtils.d.ts +10 -10
  69. package/lib/utils/ResponseUtils.js +38 -38
  70. package/lib/utils/StringUtils.d.ts +9 -9
  71. package/lib/utils/StringUtils.js +46 -46
  72. package/lib/view/asset-manifest.json +13 -13
  73. package/lib/view/assets/icons/delete_icon.svg +3 -3
  74. package/lib/view/assets/icons/flags/ic_flag_cn.svg +9 -9
  75. package/lib/view/assets/icons/flags/ic_flag_sa.svg +9 -9
  76. package/lib/view/assets/icons/flags/ic_flag_vn.svg +9 -9
  77. package/lib/view/assets/icons/info_icon.svg +3 -3
  78. package/lib/view/assets/icons/navbar/ic_banking.svg +5 -5
  79. package/lib/view/assets/icons/navbar/ic_invoice.svg +4 -4
  80. package/lib/view/assets/icons/navbar/ic_kanban.svg +7 -7
  81. package/lib/view/assets/icons/navbar/ic_menu_item.svg +8 -8
  82. package/lib/view/assets/icons/small_info_icon.svg +3 -3
  83. package/lib/view/assets/illustrations/Group 16.svg +4 -4
  84. package/lib/view/assets/illustrations/logo.svg +5 -5
  85. package/lib/view/favicon/browserconfig.xml +9 -9
  86. package/lib/view/favicon/safari-pinned-tab.svg +182 -182
  87. package/lib/view/favicon/site.webmanifest +19 -19
  88. package/lib/view/fonts/index.css +18 -18
  89. package/lib/view/index.html +1 -1
  90. package/lib/view/manifest.json +20 -20
  91. package/lib/view/robots.txt +3 -3
  92. package/lib/view/static/js/{148.b6f24fc9.chunk.js → 148.b05fe2c8.chunk.js} +1 -1
  93. package/lib/view/static/js/{705.b2b55cc3.chunk.js → 705.f86db82e.chunk.js} +1 -1
  94. package/lib/view/static/js/802.3f287a2c.chunk.js +1 -0
  95. package/lib/view/static/js/main.da8f09ec.js +2 -0
  96. package/lib/view/static/js/{main.bc5ec798.js.LICENSE.txt → main.da8f09ec.js.LICENSE.txt} +225 -223
  97. package/package.json +51 -51
  98. package/lib/view/static/js/939.f35326c5.chunk.js +0 -1
  99. package/lib/view/static/js/main.bc5ec798.js +0 -2
@@ -1,131 +1,182 @@
1
- import { Request } from "express";
2
- import { Document, Model } from "mongoose";
3
- import { ActionTypes, Virtuals } from "./helpers";
4
- declare type orderTypes = 'asc' | 'desc';
5
- declare type VirtualFieldTypes = 'password' | 'ref' | 'Array';
6
- declare type Severity = 'success' | 'info' | 'warning' | 'error';
7
- interface Parent {
8
- name: string;
9
- icon: string;
10
- }
11
- interface Action {
12
- isAccessible?: boolean;
13
- }
14
- interface ICrudOperations {
15
- index?: {
16
- before: (filter: {
17
- [key: string]: any;
18
- }, currentUser: Document) => {
19
- [key: string]: any;
20
- };
21
- };
22
- create?: {
23
- before: (params: any, currentUser: Document) => any;
24
- };
25
- show?: {
26
- after: (record: Document) => Promise<{
27
- record: Document;
28
- [key: string]: any;
29
- }>;
30
- };
31
- }
32
- export interface ActionData {
33
- record: any;
34
- currentUser: Document;
35
- resource: {
36
- name: string;
37
- path: string;
38
- repository: any;
39
- };
40
- }
41
- interface IFilters {
42
- scopes?: {
43
- isAccessible: boolean;
44
- key?: string;
45
- options?: string[];
46
- };
47
- searchBar?: {
48
- isAccessible: boolean;
49
- };
50
- }
51
- interface IFieldValue {
52
- required?: boolean;
53
- isEditable?: boolean;
54
- type?: string;
55
- }
56
- export interface IVirtualValue {
57
- type: VirtualFieldTypes;
58
- arrayType?: string;
59
- showIn: Virtuals;
60
- required: boolean;
61
- resource?: Model<any, any>;
62
- }
63
- interface IModel {
64
- virtuals?: {
65
- [key: string]: IVirtualValue;
66
- };
67
- }
68
- interface ActionOptions {
69
- show?: Action;
70
- new?: Action;
71
- edit?: Action;
72
- delete?: Action;
73
- bulkDelete?: Action;
74
- extras?: ExtraAction[];
75
- }
76
- interface ExtraAction {
77
- key: string;
78
- name: string;
79
- /**
80
- * Icon of this action.
81
- * @reference 'https://mui.com/material-ui/material-icons/'
82
- */
83
- icon: string;
84
- actionType: ActionTypes;
85
- /**
86
- * Guard message that appears before executing the action to confirm execution.
87
- * @default 'No guard message'
88
- */
89
- guard?: string;
90
- /**
91
- * Alert message appear after executing this action.
92
- * @default 'Action was executed successfully'
93
- */
94
- message?: string;
95
- /**
96
- * The severity of the alert. This defines the color and icon used.
97
- * @default 'success'
98
- */
99
- severity?: Severity;
100
- isVisible?: (data: ActionData) => boolean;
101
- handler: (req: Request, res: any, data: ActionData) => Promise<any>;
102
- }
103
- export interface IResourceFile {
104
- properties: {
105
- resource: Model<any, any>;
106
- modelName: string;
107
- name?: string;
108
- title?: string;
109
- defaultOrderBy?: string;
110
- defaultrowsPerPage?: number;
111
- defaultOrder?: orderTypes;
112
- parent?: Parent;
113
- hiddenProperties?: string[];
114
- actions?: ActionOptions;
115
- filters?: IFilters;
116
- crudOperations?: ICrudOperations;
117
- keysTranslations?: {
118
- [key: string]: any;
119
- };
120
- actionsTranslations?: {
121
- [key: string]: any;
122
- };
123
- model?: {
124
- [key: string]: IFieldValue;
125
- } | IModel;
126
- };
127
- listProperties?: string[];
128
- showProperties?: string[];
129
- formProperties?: string[];
130
- }
131
- export {};
1
+ import { Request } from "express";
2
+ import { Document, Model } from "mongoose";
3
+ import { IRequest } from "../middlewares/isAuth";
4
+ import { ActionTypes, FieldTypes, Virtuals } from "./helpers";
5
+ declare type orderTypes = 'asc' | 'desc';
6
+ declare type VirtualFieldTypes = 'password' | 'ref' | 'Array';
7
+ declare type Severity = 'success' | 'info' | 'warning' | 'error';
8
+ interface IAutoScope {
9
+ /**
10
+ * Key of property as specified in the database
11
+ */
12
+ key: string;
13
+ /**
14
+ * Array of values that this key can have
15
+ */
16
+ options: string[];
17
+ }
18
+ interface IManualScope {
19
+ /**
20
+ * Array of values that will be appeared in the scope
21
+ */
22
+ options: string[];
23
+ /**
24
+ * A handler that will be called when scope filter is used. This handler should perform a switch case on the specified options values, each case set the filter on its way.
25
+ */
26
+ handler: (filter: {
27
+ [key: string]: any;
28
+ }, scope: string) => {
29
+ [key: string]: any;
30
+ };
31
+ }
32
+ interface Parent {
33
+ /**
34
+ * Name of the parent
35
+ */
36
+ name: string;
37
+ /**
38
+ * Icon of the parent. You can get the icons from
39
+ * @link https://mui.com/material-ui/material-icons/
40
+ */
41
+ icon: string;
42
+ }
43
+ interface Action {
44
+ /**
45
+ * Specify if this action is accessible or not.
46
+ * @default True is the default for show, edit, delete, and new while false for bulk delete. You can ovveride any of these values here.
47
+ */
48
+ isAccessible?: boolean;
49
+ }
50
+ interface ICrudOperations {
51
+ index?: {
52
+ /**
53
+ * Before handler that gives you the access to the filter object. You can add to the filter object any key and value that will be used in the filter query before getting the records for list. You should return the filter object
54
+ */
55
+ before: (req: IRequest, filter: {
56
+ [key: string]: any;
57
+ }, currentUser: Document) => {
58
+ [key: string]: any;
59
+ };
60
+ };
61
+ create?: {
62
+ /**
63
+ * Before handler that is called before creating a new record. This function gives you the access to the record params before saving it, you can perform any update to the params before saving it. This function should return the params
64
+ */
65
+ before: (req: IRequest, params: any, currentUser: Document) => any;
66
+ };
67
+ show?: {
68
+ after: (req: IRequest, record: Document) => Promise<{
69
+ record: Document;
70
+ [key: string]: any;
71
+ }>;
72
+ };
73
+ }
74
+ export interface ActionData {
75
+ record: any;
76
+ currentUser: Document;
77
+ resource: {
78
+ name: string;
79
+ path: string;
80
+ repository: any;
81
+ };
82
+ }
83
+ interface IFilters {
84
+ scopes?: {
85
+ isAccessible: boolean;
86
+ auto?: IAutoScope;
87
+ manual?: IManualScope;
88
+ };
89
+ searchBar?: {
90
+ isAccessible: boolean;
91
+ };
92
+ }
93
+ export interface IFieldValue {
94
+ required?: boolean;
95
+ isEditable?: boolean;
96
+ type?: string;
97
+ /**
98
+ * Specify the allowed country codes. Only mandatory if the type is phone number
99
+ * Alert message appear after executing this action.
100
+ * ex: ["sa", "eg", ...]
101
+ */
102
+ countryCodes?: string[];
103
+ arrayType?: FieldTypes;
104
+ mediaUploader?: boolean;
105
+ }
106
+ export interface IVirtualValue {
107
+ type: VirtualFieldTypes;
108
+ arrayType?: string;
109
+ showIn: Virtuals;
110
+ required: boolean;
111
+ resource?: Model<any, any>;
112
+ }
113
+ interface IModel {
114
+ virtuals?: {
115
+ [key: string]: IVirtualValue;
116
+ };
117
+ }
118
+ interface ActionOptions {
119
+ show?: Action;
120
+ new?: Action;
121
+ edit?: Action;
122
+ delete?: Action;
123
+ bulkDelete?: Action;
124
+ extras?: ExtraAction[];
125
+ }
126
+ interface ExtraAction {
127
+ key: string;
128
+ name: string;
129
+ /**
130
+ * Icon of this action.
131
+ * @reference 'https://mui.com/material-ui/material-icons/'
132
+ */
133
+ icon: string;
134
+ actionType: ActionTypes;
135
+ /**
136
+ * Guard message that appears before executing the action to confirm execution.
137
+ * @default 'No guard message'
138
+ */
139
+ guard?: string;
140
+ /**
141
+ * Alert message appear after executing this action.
142
+ * @default 'Action was executed successfully'
143
+ */
144
+ message?: string;
145
+ /**
146
+ * The severity of the alert. This defines the color and icon used.
147
+ * @default 'success'
148
+ */
149
+ severity?: Severity;
150
+ isVisible?: (data: ActionData) => boolean;
151
+ handler: (req: Request, res: any, data: ActionData) => Promise<any>;
152
+ }
153
+ export interface IResourceFile {
154
+ properties: {
155
+ resource: Model<any, any>;
156
+ modelName: string;
157
+ name?: string;
158
+ title?: string;
159
+ defaultOrderBy?: string;
160
+ defaultrowsPerPage?: number;
161
+ defaultOrder?: orderTypes;
162
+ parent?: Parent;
163
+ hiddenProperties?: string[];
164
+ actions?: ActionOptions;
165
+ filters?: IFilters;
166
+ crudOperations?: ICrudOperations;
167
+ keysTranslations?: {
168
+ [key: string]: any;
169
+ };
170
+ actionsTranslations?: {
171
+ [key: string]: any;
172
+ };
173
+ model?: {
174
+ [key: string]: IFieldValue;
175
+ } | IModel;
176
+ };
177
+ listProperties?: string[];
178
+ showProperties?: string[];
179
+ formProperties?: string[];
180
+ filterProperties?: string[];
181
+ }
182
+ export {};
@@ -1,2 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,15 +1,32 @@
1
- export declare enum Virtuals {
2
- SHOW = "SHOW",
3
- LIST = "LIST",
4
- FORM = "FORM"
5
- }
6
- export declare enum ActionNames {
7
- SHOW = "SHOW",
8
- LIST = "LIST",
9
- NEW = "NEW",
10
- EDIT = "EDIT"
11
- }
12
- export declare enum ActionTypes {
13
- RECORD = "record",
14
- Resource = "resource"
15
- }
1
+ export declare enum Virtuals {
2
+ SHOW = "SHOW",
3
+ LIST = "LIST",
4
+ FORM = "FORM"
5
+ }
6
+ export declare enum ActionNames {
7
+ SHOW = "SHOW",
8
+ LIST = "LIST",
9
+ NEW = "NEW",
10
+ EDIT = "EDIT"
11
+ }
12
+ export declare enum ActionTypes {
13
+ RECORD = "record",
14
+ Resource = "resource"
15
+ }
16
+ export declare enum FieldTypes {
17
+ STRING = "String",
18
+ NUMBER = "Number",
19
+ ENUM = "enum",
20
+ REFERENCE = "ref",
21
+ DATE = "Date",
22
+ PASSWORD = "password",
23
+ BOOLEAN = "Boolean",
24
+ OBJECTID = "ObjectID",
25
+ NESTEDSCHEMA = "nestedSchema",
26
+ ARRAY = "Array",
27
+ IMAGE = "image",
28
+ LOCALIZEDSTRING = "localizedString",
29
+ PHONENUMBER = "phoneNumber",
30
+ COLOR = "color",
31
+ TIMEPICKER = "timePicker"
32
+ }
@@ -1,21 +1,39 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ActionTypes = exports.ActionNames = exports.Virtuals = void 0;
4
- var Virtuals;
5
- (function (Virtuals) {
6
- Virtuals["SHOW"] = "SHOW";
7
- Virtuals["LIST"] = "LIST";
8
- Virtuals["FORM"] = "FORM";
9
- })(Virtuals = exports.Virtuals || (exports.Virtuals = {}));
10
- var ActionNames;
11
- (function (ActionNames) {
12
- ActionNames["SHOW"] = "SHOW";
13
- ActionNames["LIST"] = "LIST";
14
- ActionNames["NEW"] = "NEW";
15
- ActionNames["EDIT"] = "EDIT";
16
- })(ActionNames = exports.ActionNames || (exports.ActionNames = {}));
17
- var ActionTypes;
18
- (function (ActionTypes) {
19
- ActionTypes["RECORD"] = "record";
20
- ActionTypes["Resource"] = "resource";
21
- })(ActionTypes = exports.ActionTypes || (exports.ActionTypes = {}));
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FieldTypes = exports.ActionTypes = exports.ActionNames = exports.Virtuals = void 0;
4
+ var Virtuals;
5
+ (function (Virtuals) {
6
+ Virtuals["SHOW"] = "SHOW";
7
+ Virtuals["LIST"] = "LIST";
8
+ Virtuals["FORM"] = "FORM";
9
+ })(Virtuals = exports.Virtuals || (exports.Virtuals = {}));
10
+ var ActionNames;
11
+ (function (ActionNames) {
12
+ ActionNames["SHOW"] = "SHOW";
13
+ ActionNames["LIST"] = "LIST";
14
+ ActionNames["NEW"] = "NEW";
15
+ ActionNames["EDIT"] = "EDIT";
16
+ })(ActionNames = exports.ActionNames || (exports.ActionNames = {}));
17
+ var ActionTypes;
18
+ (function (ActionTypes) {
19
+ ActionTypes["RECORD"] = "record";
20
+ ActionTypes["Resource"] = "resource";
21
+ })(ActionTypes = exports.ActionTypes || (exports.ActionTypes = {}));
22
+ var FieldTypes;
23
+ (function (FieldTypes) {
24
+ FieldTypes["STRING"] = "String";
25
+ FieldTypes["NUMBER"] = "Number";
26
+ FieldTypes["ENUM"] = "enum";
27
+ FieldTypes["REFERENCE"] = "ref";
28
+ FieldTypes["DATE"] = "Date";
29
+ FieldTypes["PASSWORD"] = "password";
30
+ FieldTypes["BOOLEAN"] = "Boolean";
31
+ FieldTypes["OBJECTID"] = "ObjectID";
32
+ FieldTypes["NESTEDSCHEMA"] = "nestedSchema";
33
+ FieldTypes["ARRAY"] = "Array";
34
+ FieldTypes["IMAGE"] = "image";
35
+ FieldTypes["LOCALIZEDSTRING"] = "localizedString";
36
+ FieldTypes["PHONENUMBER"] = "phoneNumber";
37
+ FieldTypes["COLOR"] = "color";
38
+ FieldTypes["TIMEPICKER"] = "timePicker";
39
+ })(FieldTypes = exports.FieldTypes || (exports.FieldTypes = {}));
@@ -1,2 +1,2 @@
1
- import { IResourceFile } from "../types/IResourceFile";
2
- export declare const getResource: (modelName: string, resources: IResourceFile[]) => IResourceFile | undefined;
1
+ import { IResourceFile } from "../types/IResourceFile";
2
+ export declare const getResource: (modelName: string, resources: IResourceFile[]) => IResourceFile | undefined;
@@ -1,7 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getResource = void 0;
4
- const getResource = (modelName, resources) => {
5
- return resources.find(resource => resource.properties.modelName === modelName);
6
- };
7
- exports.getResource = getResource;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getResource = void 0;
4
+ const getResource = (modelName, resources) => {
5
+ return resources.find(resource => resource.properties.modelName === modelName);
6
+ };
7
+ exports.getResource = getResource;
@@ -1,10 +1,10 @@
1
- import { ISaveError } from '../repositories/SaveResult';
2
- import { Response } from 'express';
3
- export default class ResponseUtils {
4
- static send(res: Response, status: number, message: string, data?: object, errors?: ISaveError[]): Response<any, Record<string, any>>;
5
- static created(res: Response, data: object): void;
6
- static ok(res: Response, data: object): void;
7
- static unauthorized(res: Response): void;
8
- static unprocessable(res: Response, message: string, errors: ISaveError[]): void;
9
- static notFound(res: Response, message: string, errors: ISaveError[]): void;
10
- }
1
+ import { ISaveError } from '../repositories/SaveResult';
2
+ import { Response } from 'express';
3
+ export default class ResponseUtils {
4
+ static send(res: Response, status: number, message: string, data?: object, errors?: ISaveError[]): Response<any, Record<string, any>>;
5
+ static created(res: Response, data: object): void;
6
+ static ok(res: Response, data: object): void;
7
+ static unauthorized(res: Response): void;
8
+ static unprocessable(res: Response, message: string, errors: ISaveError[]): void;
9
+ static notFound(res: Response, message: string, errors: ISaveError[]): void;
10
+ }
@@ -1,38 +1,38 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class ResponseUtils {
4
- static send(res, status, message, data, errors) {
5
- const splittedMessage = message.split(', ');
6
- return res.format({
7
- json: () => {
8
- res.status(status).json({
9
- meta: {
10
- status,
11
- message: res.__(splittedMessage[0], { attribute: splittedMessage[1] })
12
- },
13
- data,
14
- errors
15
- });
16
- },
17
- default: () => {
18
- res.status(406).send();
19
- }
20
- });
21
- }
22
- static created(res, data) {
23
- this.send(res, 201, 'Created', data);
24
- }
25
- static ok(res, data) {
26
- this.send(res, 200, 'Ok', data);
27
- }
28
- static unauthorized(res) {
29
- this.send(res, 401, 'Unauthenticated');
30
- }
31
- static unprocessable(res, message, errors) {
32
- this.send(res, 422, message, {}, errors);
33
- }
34
- static notFound(res, message, errors) {
35
- this.send(res, 404, message, {}, errors);
36
- }
37
- }
38
- exports.default = ResponseUtils;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class ResponseUtils {
4
+ static send(res, status, message, data, errors) {
5
+ const splittedMessage = message.split(', ');
6
+ return res.format({
7
+ json: () => {
8
+ res.status(status).json({
9
+ meta: {
10
+ status,
11
+ message: res.__(splittedMessage[0], { attribute: splittedMessage[1] })
12
+ },
13
+ data,
14
+ errors
15
+ });
16
+ },
17
+ default: () => {
18
+ res.status(406).send();
19
+ }
20
+ });
21
+ }
22
+ static created(res, data) {
23
+ this.send(res, 201, 'Created', data);
24
+ }
25
+ static ok(res, data) {
26
+ this.send(res, 200, 'Ok', data);
27
+ }
28
+ static unauthorized(res) {
29
+ this.send(res, 401, 'Unauthenticated');
30
+ }
31
+ static unprocessable(res, message, errors) {
32
+ this.send(res, 422, message, {}, errors);
33
+ }
34
+ static notFound(res, message, errors) {
35
+ this.send(res, 404, message, {}, errors);
36
+ }
37
+ }
38
+ exports.default = ResponseUtils;
@@ -1,9 +1,9 @@
1
- export default class StringUtils {
2
- static convertCamelCaseToWord(camelCaseWord: string): string;
3
- static checkRefId(word: string): boolean;
4
- static lowerCaseFirstLetter(word: string): string;
5
- static upperCaseFirstLetter(word: string): string;
6
- static removeResourceWord(word: string): string;
7
- static getRefPath(word: string): string;
8
- static getPopulatedString(populatedString: string, addedString: string): string;
9
- }
1
+ export default class StringUtils {
2
+ static convertCamelCaseToWord(camelCaseWord: string): string;
3
+ static checkRefId(word: string): boolean;
4
+ static lowerCaseFirstLetter(word: string): string;
5
+ static upperCaseFirstLetter(word: string): string;
6
+ static removeResourceWord(word: string): string;
7
+ static getRefPath(word: string): string;
8
+ static getPopulatedString(populatedString: string, addedString: string): string;
9
+ }
@@ -1,46 +1,46 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var pluralize = require('pluralize');
4
- class StringUtils {
5
- static convertCamelCaseToWord(camelCaseWord) {
6
- if (camelCaseWord === '_id') {
7
- return 'Id';
8
- }
9
- var result = camelCaseWord.replace(/([A-Z])/g, " $1");
10
- var word = result.charAt(0).toUpperCase() + result.slice(1);
11
- if (word.charAt(0) === ' ') {
12
- word = word.substring(1);
13
- }
14
- return word;
15
- }
16
- static checkRefId(word) {
17
- const check = word.slice(-2) === 'Id';
18
- return check;
19
- }
20
- static lowerCaseFirstLetter(word) {
21
- return word.charAt(0).toLocaleLowerCase() + word.slice(1);
22
- }
23
- static upperCaseFirstLetter(word) {
24
- return word.charAt(0).toUpperCase() + word.slice(1);
25
- }
26
- static removeResourceWord(word) {
27
- return this.lowerCaseFirstLetter(word.split('Resource')[0]);
28
- }
29
- static getRefPath(word) {
30
- const check = word.slice(-2) === 'Id';
31
- if (check) {
32
- return word.slice(0, -2);
33
- }
34
- return this.lowerCaseFirstLetter(pluralize.singular(word));
35
- }
36
- static getPopulatedString(populatedString, addedString) {
37
- if (populatedString.length === 0) {
38
- populatedString = populatedString + addedString;
39
- }
40
- else {
41
- populatedString = populatedString + ' ' + addedString;
42
- }
43
- return populatedString;
44
- }
45
- }
46
- exports.default = StringUtils;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var pluralize = require('pluralize');
4
+ class StringUtils {
5
+ static convertCamelCaseToWord(camelCaseWord) {
6
+ if (camelCaseWord === '_id') {
7
+ return 'Id';
8
+ }
9
+ var result = camelCaseWord.replace(/([A-Z])/g, " $1");
10
+ var word = result.charAt(0).toUpperCase() + result.slice(1);
11
+ if (word.charAt(0) === ' ') {
12
+ word = word.substring(1);
13
+ }
14
+ return word;
15
+ }
16
+ static checkRefId(word) {
17
+ const check = word.slice(-2) === 'Id';
18
+ return check;
19
+ }
20
+ static lowerCaseFirstLetter(word) {
21
+ return word.charAt(0).toLocaleLowerCase() + word.slice(1);
22
+ }
23
+ static upperCaseFirstLetter(word) {
24
+ return word.charAt(0).toUpperCase() + word.slice(1);
25
+ }
26
+ static removeResourceWord(word) {
27
+ return this.lowerCaseFirstLetter(word.split('Resource')[0]);
28
+ }
29
+ static getRefPath(word) {
30
+ const check = word.slice(-2) === 'Id';
31
+ if (check) {
32
+ return word.slice(0, -2);
33
+ }
34
+ return this.lowerCaseFirstLetter(pluralize.singular(word));
35
+ }
36
+ static getPopulatedString(populatedString, addedString) {
37
+ if (populatedString.length === 0) {
38
+ populatedString = populatedString + addedString;
39
+ }
40
+ else {
41
+ populatedString = populatedString + ' ' + addedString;
42
+ }
43
+ return populatedString;
44
+ }
45
+ }
46
+ exports.default = StringUtils;