@flusys/nestjs-form-builder 7.1.0 → 8.0.0-beta.1
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/config/index.d.ts +3 -3
- package/controllers/form-result.controller.d.ts +3 -3
- package/controllers/form.controller.d.ts +3 -3
- package/controllers/index.d.ts +2 -2
- package/docs/form-builder-swagger.config.d.ts +2 -2
- package/docs/index.d.ts +1 -1
- package/dtos/form.dto.d.ts +1 -1
- package/dtos/index.d.ts +2 -2
- package/entities/form-with-company.entity.d.ts +1 -1
- package/entities/form.entity.d.ts +1 -1
- package/entities/index.d.ts +7 -7
- package/enums/index.d.ts +1 -1
- package/fesm/262.js +1841 -0
- package/fesm/98.js +807 -0
- package/fesm/config/index.js +98 -3
- package/fesm/controllers/index.js +14 -2
- package/fesm/docs/index.js +171 -1
- package/fesm/dtos/index.js +571 -2
- package/fesm/entities/index.js +342 -10
- package/fesm/enums/index.js +38 -1
- package/fesm/index.js +482 -10
- package/fesm/interfaces/index.js +17 -3
- package/fesm/modules/index.js +178 -1
- package/fesm/runtime.js +85 -0
- package/fesm/services/index.js +35 -4
- package/index.d.ts +10 -10
- package/interfaces/form-builder-module.interface.d.ts +3 -3
- package/interfaces/form-result.interface.d.ts +1 -1
- package/interfaces/form.interface.d.ts +2 -2
- package/interfaces/index.d.ts +3 -3
- package/modules/form-builder.module.d.ts +2 -2
- package/modules/index.d.ts +1 -1
- package/package.json +26 -36
- package/services/form-builder-config.service.d.ts +4 -4
- package/services/form-builder-datasource.provider.d.ts +3 -3
- package/services/form-result.service.d.ts +6 -6
- package/services/form.service.d.ts +7 -7
- package/services/index.d.ts +4 -4
- package/utils/index.d.ts +2 -2
- package/utils/permission.utils.d.ts +1 -1
- package/cjs/config/event-actions.js +0 -33
- package/cjs/config/form-builder.constants.js +0 -13
- package/cjs/config/index.js +0 -20
- package/cjs/config/message-keys.js +0 -38
- package/cjs/controllers/form-result.controller.js +0 -281
- package/cjs/controllers/form-result.controller.spec.js +0 -257
- package/cjs/controllers/form.controller.js +0 -231
- package/cjs/controllers/form.controller.spec.js +0 -212
- package/cjs/controllers/index.js +0 -19
- package/cjs/docs/form-builder-swagger.config.js +0 -150
- package/cjs/docs/form-builder-swagger.config.spec.js +0 -75
- package/cjs/docs/index.js +0 -11
- package/cjs/dtos/form-result.dto.js +0 -248
- package/cjs/dtos/form.dto.js +0 -270
- package/cjs/dtos/index.js +0 -19
- package/cjs/entities/form-result.entity.js +0 -100
- package/cjs/entities/form-with-company.entity.js +0 -65
- package/cjs/entities/form.entity.js +0 -127
- package/cjs/entities/index.js +0 -52
- package/cjs/entities/index.spec.js +0 -18
- package/cjs/enums/form-access-type.enum.js +0 -19
- package/cjs/enums/index.js +0 -18
- package/cjs/index.js +0 -28
- package/cjs/interfaces/form-builder-module.interface.js +0 -4
- package/cjs/interfaces/form-result.interface.js +0 -4
- package/cjs/interfaces/form.interface.js +0 -4
- package/cjs/interfaces/index.js +0 -20
- package/cjs/modules/form-builder.module.js +0 -136
- package/cjs/modules/form-builder.module.spec.js +0 -133
- package/cjs/modules/index.js +0 -18
- package/cjs/services/form-builder-config.service.js +0 -69
- package/cjs/services/form-builder-config.service.spec.js +0 -121
- package/cjs/services/form-builder-datasource.provider.js +0 -125
- package/cjs/services/form-builder-datasource.provider.spec.js +0 -147
- package/cjs/services/form-result.service.js +0 -366
- package/cjs/services/form-result.service.spec.js +0 -823
- package/cjs/services/form.service.js +0 -341
- package/cjs/services/form.service.spec.js +0 -746
- package/cjs/services/index.js +0 -21
- package/cjs/utils/computed-field.utils.js +0 -199
- package/cjs/utils/computed-field.utils.spec.js +0 -1205
- package/cjs/utils/index.js +0 -19
- package/cjs/utils/permission.utils.js +0 -44
- package/cjs/utils/permission.utils.spec.js +0 -118
- package/fesm/config/event-actions.js +0 -12
- package/fesm/config/form-builder.constants.js +0 -3
- package/fesm/config/message-keys.js +0 -20
- package/fesm/controllers/form-result.controller.js +0 -271
- package/fesm/controllers/form-result.controller.spec.js +0 -253
- package/fesm/controllers/form.controller.js +0 -221
- package/fesm/controllers/form.controller.spec.js +0 -208
- package/fesm/docs/form-builder-swagger.config.js +0 -146
- package/fesm/docs/form-builder-swagger.config.spec.js +0 -71
- package/fesm/dtos/form-result.dto.js +0 -215
- package/fesm/dtos/form.dto.js +0 -243
- package/fesm/entities/form-result.entity.js +0 -90
- package/fesm/entities/form-with-company.entity.js +0 -55
- package/fesm/entities/form.entity.js +0 -117
- package/fesm/entities/index.spec.js +0 -14
- package/fesm/enums/form-access-type.enum.js +0 -9
- package/fesm/interfaces/form-builder-module.interface.js +0 -3
- package/fesm/interfaces/form-result.interface.js +0 -6
- package/fesm/interfaces/form.interface.js +0 -3
- package/fesm/modules/form-builder.module.js +0 -126
- package/fesm/modules/form-builder.module.spec.js +0 -129
- package/fesm/services/form-builder-config.service.js +0 -59
- package/fesm/services/form-builder-config.service.spec.js +0 -117
- package/fesm/services/form-builder-datasource.provider.js +0 -74
- package/fesm/services/form-builder-datasource.provider.spec.js +0 -143
- package/fesm/services/form-result.service.js +0 -356
- package/fesm/services/form-result.service.spec.js +0 -778
- package/fesm/services/form.service.js +0 -331
- package/fesm/services/form.service.spec.js +0 -701
- package/fesm/utils/computed-field.utils.js +0 -195
- package/fesm/utils/computed-field.utils.spec.js +0 -1201
- package/fesm/utils/index.js +0 -2
- package/fesm/utils/permission.utils.js +0 -42
- package/fesm/utils/permission.utils.spec.js +0 -114
package/cjs/utils/index.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
_export_star(require("./permission.utils"), exports);
|
|
6
|
-
_export_star(require("./computed-field.utils"), exports);
|
|
7
|
-
function _export_star(from, to) {
|
|
8
|
-
Object.keys(from).forEach(function(k) {
|
|
9
|
-
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
10
|
-
Object.defineProperty(to, k, {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function() {
|
|
13
|
-
return from[k];
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
return from;
|
|
19
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "validateUserPermissions", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return validateUserPermissions;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _config = require("../config");
|
|
12
|
-
const _common = require("@nestjs/common");
|
|
13
|
-
const CACHE_PREFIX = 'permissions';
|
|
14
|
-
/**
|
|
15
|
-
* Build permission cache key for a user
|
|
16
|
-
* Uses same cache key format as PermissionGuard in nestjs-shared
|
|
17
|
-
*/ function buildPermissionCacheKey(user, enableCompanyFeature) {
|
|
18
|
-
if (enableCompanyFeature && user.companyId) {
|
|
19
|
-
return `${CACHE_PREFIX}:company:${user.companyId}:branch:${user.branchId || 'null'}:user:${user.id}`;
|
|
20
|
-
}
|
|
21
|
-
return `${CACHE_PREFIX}:user:${user.id}`;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Get user permissions from cache
|
|
25
|
-
* Fail-closed: if cache fails, deny access rather than allowing potentially unauthorized access
|
|
26
|
-
*/ async function getUserPermissionsFromCache(user, cacheManager, enableCompanyFeature) {
|
|
27
|
-
const cacheKey = buildPermissionCacheKey(user, enableCompanyFeature);
|
|
28
|
-
try {
|
|
29
|
-
const permissions = await cacheManager.get(cacheKey);
|
|
30
|
-
return permissions ?? [];
|
|
31
|
-
} catch {
|
|
32
|
-
throw new _common.ForbiddenException({
|
|
33
|
-
message: 'Unable to verify permissions. Please try again.',
|
|
34
|
-
messageKey: _config.FORM_MESSAGES.PERMISSION_CHECK_FAILED
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
async function validateUserPermissions(user, requiredPermissions, cacheManager, enableCompanyFeature) {
|
|
39
|
-
if (!requiredPermissions.length) {
|
|
40
|
-
return true;
|
|
41
|
-
}
|
|
42
|
-
const userPermissions = await getUserPermissionsFromCache(user, cacheManager, enableCompanyFeature);
|
|
43
|
-
return requiredPermissions.some((perm)=>userPermissions.includes(perm));
|
|
44
|
-
}
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
const _common = require("@nestjs/common");
|
|
6
|
-
const _loggedusermock = require("@test-utils/mocks/logged-user.mock");
|
|
7
|
-
const _permissionutils = require("./permission.utils");
|
|
8
|
-
function buildMockCache() {
|
|
9
|
-
return {
|
|
10
|
-
get: jest.fn(),
|
|
11
|
-
set: jest.fn(),
|
|
12
|
-
del: jest.fn()
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
describe('validateUserPermissions', ()=>{
|
|
16
|
-
it('returns true immediately without touching the cache when no permissions are required', async ()=>{
|
|
17
|
-
const cache = buildMockCache();
|
|
18
|
-
const result = await (0, _permissionutils.validateUserPermissions)((0, _loggedusermock.buildMockUser)(), [], cache, false);
|
|
19
|
-
expect(result).toBe(true);
|
|
20
|
-
expect(cache.get).not.toHaveBeenCalled();
|
|
21
|
-
});
|
|
22
|
-
it('returns true when the user has at least one of the required permissions', async ()=>{
|
|
23
|
-
const cache = buildMockCache();
|
|
24
|
-
cache.get.mockResolvedValue([
|
|
25
|
-
'hr.survey.submit',
|
|
26
|
-
'other.permission'
|
|
27
|
-
]);
|
|
28
|
-
const result = await (0, _permissionutils.validateUserPermissions)((0, _loggedusermock.buildMockUser)(), [
|
|
29
|
-
'hr.survey.submit',
|
|
30
|
-
'employee.feedback.submit'
|
|
31
|
-
], cache, false);
|
|
32
|
-
expect(result).toBe(true);
|
|
33
|
-
});
|
|
34
|
-
it('returns false when the user has none of the required permissions', async ()=>{
|
|
35
|
-
const cache = buildMockCache();
|
|
36
|
-
cache.get.mockResolvedValue([
|
|
37
|
-
'some.other.permission'
|
|
38
|
-
]);
|
|
39
|
-
const result = await (0, _permissionutils.validateUserPermissions)((0, _loggedusermock.buildMockUser)(), [
|
|
40
|
-
'hr.survey.submit'
|
|
41
|
-
], cache, false);
|
|
42
|
-
expect(result).toBe(false);
|
|
43
|
-
});
|
|
44
|
-
it('treats a missing cache entry as no permissions (returns false)', async ()=>{
|
|
45
|
-
const cache = buildMockCache();
|
|
46
|
-
cache.get.mockResolvedValue(undefined);
|
|
47
|
-
const result = await (0, _permissionutils.validateUserPermissions)((0, _loggedusermock.buildMockUser)(), [
|
|
48
|
-
'hr.survey.submit'
|
|
49
|
-
], cache, false);
|
|
50
|
-
expect(result).toBe(false);
|
|
51
|
-
});
|
|
52
|
-
it('fails closed with a ForbiddenException when the cache lookup throws', async ()=>{
|
|
53
|
-
const cache = buildMockCache();
|
|
54
|
-
cache.get.mockRejectedValue(new Error('redis down'));
|
|
55
|
-
await expect((0, _permissionutils.validateUserPermissions)((0, _loggedusermock.buildMockUser)(), [
|
|
56
|
-
'hr.survey.submit'
|
|
57
|
-
], cache, false)).rejects.toMatchObject({
|
|
58
|
-
response: expect.objectContaining({
|
|
59
|
-
messageKey: 'form.permission.check.failed'
|
|
60
|
-
})
|
|
61
|
-
});
|
|
62
|
-
await expect((0, _permissionutils.validateUserPermissions)((0, _loggedusermock.buildMockUser)(), [
|
|
63
|
-
'hr.survey.submit'
|
|
64
|
-
], cache, false)).rejects.toBeInstanceOf(_common.ForbiddenException);
|
|
65
|
-
});
|
|
66
|
-
describe('cache key construction', ()=>{
|
|
67
|
-
it('uses a company/branch/user scoped key when the company feature is enabled and both are present', async ()=>{
|
|
68
|
-
const cache = buildMockCache();
|
|
69
|
-
cache.get.mockResolvedValue([]);
|
|
70
|
-
const user = (0, _loggedusermock.buildMockUser)({
|
|
71
|
-
companyId: 'company-1',
|
|
72
|
-
branchId: 'branch-1',
|
|
73
|
-
id: 'user-1'
|
|
74
|
-
});
|
|
75
|
-
await (0, _permissionutils.validateUserPermissions)(user, [
|
|
76
|
-
'perm.read'
|
|
77
|
-
], cache, true);
|
|
78
|
-
expect(cache.get).toHaveBeenCalledWith('permissions:company:company-1:branch:branch-1:user:user-1');
|
|
79
|
-
});
|
|
80
|
-
it('uses "null" as the branch placeholder when branchId is missing under the company feature', async ()=>{
|
|
81
|
-
const cache = buildMockCache();
|
|
82
|
-
cache.get.mockResolvedValue([]);
|
|
83
|
-
const user = (0, _loggedusermock.buildMockUser)({
|
|
84
|
-
companyId: 'company-1',
|
|
85
|
-
branchId: undefined,
|
|
86
|
-
id: 'user-1'
|
|
87
|
-
});
|
|
88
|
-
await (0, _permissionutils.validateUserPermissions)(user, [
|
|
89
|
-
'perm.read'
|
|
90
|
-
], cache, true);
|
|
91
|
-
expect(cache.get).toHaveBeenCalledWith('permissions:company:company-1:branch:null:user:user-1');
|
|
92
|
-
});
|
|
93
|
-
it('falls back to a plain user-scoped key when the company feature is enabled but companyId is missing', async ()=>{
|
|
94
|
-
const cache = buildMockCache();
|
|
95
|
-
cache.get.mockResolvedValue([]);
|
|
96
|
-
const user = (0, _loggedusermock.buildMockUser)({
|
|
97
|
-
companyId: undefined,
|
|
98
|
-
id: 'user-1'
|
|
99
|
-
});
|
|
100
|
-
await (0, _permissionutils.validateUserPermissions)(user, [
|
|
101
|
-
'perm.read'
|
|
102
|
-
], cache, true);
|
|
103
|
-
expect(cache.get).toHaveBeenCalledWith('permissions:user:user-1');
|
|
104
|
-
});
|
|
105
|
-
it('uses a plain user-scoped key when the company feature is disabled', async ()=>{
|
|
106
|
-
const cache = buildMockCache();
|
|
107
|
-
cache.get.mockResolvedValue([]);
|
|
108
|
-
const user = (0, _loggedusermock.buildMockUser)({
|
|
109
|
-
companyId: 'company-1',
|
|
110
|
-
id: 'user-1'
|
|
111
|
-
});
|
|
112
|
-
await (0, _permissionutils.validateUserPermissions)(user, [
|
|
113
|
-
'perm.read'
|
|
114
|
-
], cache, false);
|
|
115
|
-
expect(cache.get).toHaveBeenCalledWith('permissions:user:user-1');
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
});
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Domain event actions published by the form builder module, alongside the
|
|
3
|
-
* CRUD lifecycle actions every ApiService emits.
|
|
4
|
-
*/ export const FORM_BUILDER_EVENT_ACTIONS = {
|
|
5
|
-
SUBMITTED: 'submitted',
|
|
6
|
-
DRAFT_SAVED: 'draft-saved'
|
|
7
|
-
};
|
|
8
|
-
/** Every entity the form builder module publishes under */ export const FORM_BUILDER_EVENT_ENTITIES = {
|
|
9
|
-
FORM: 'form',
|
|
10
|
-
FORM_RESULT: 'form_result'
|
|
11
|
-
};
|
|
12
|
-
export const FORM_BUILDER_EVENT_MODULE = 'form-builder';
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
// ==================== FORM BUILDER MODULE MESSAGE KEYS ====================
|
|
2
|
-
export const FORM_MESSAGES = {
|
|
3
|
-
NOT_FOUND: 'form.not.found',
|
|
4
|
-
NOT_PUBLIC: 'form.not.public',
|
|
5
|
-
AUTH_REQUIRED: 'form.auth.required',
|
|
6
|
-
ACCESS_DENIED: 'form.access.denied',
|
|
7
|
-
INVALID_ACCESS_TYPE: 'form.invalid.access.type',
|
|
8
|
-
PERMISSION_CHECK_FAILED: 'form.permission.check.failed',
|
|
9
|
-
GET_SUCCESS: 'form.get.success',
|
|
10
|
-
GET_ACCESS_INFO_SUCCESS: 'form.get.access.info.success'
|
|
11
|
-
};
|
|
12
|
-
export const FORM_RESULT_MESSAGES = {
|
|
13
|
-
GET_ALL_SUCCESS: 'form.result.get.all.success',
|
|
14
|
-
NOT_FOUND: 'form.result.not.found',
|
|
15
|
-
HAS_SUBMITTED_SUCCESS: 'form.result.has.submitted.success',
|
|
16
|
-
HAS_NOT_SUBMITTED_SUCCESS: 'form.result.has.not.submitted.success',
|
|
17
|
-
SUBMIT_SUCCESS: 'form.result.submit.success',
|
|
18
|
-
DRAFT_GET_SUCCESS: 'form.result.draft.get.success',
|
|
19
|
-
DRAFT_UPDATE_SUCCESS: 'form.result.draft.update.success'
|
|
20
|
-
};
|
|
@@ -1,271 +0,0 @@
|
|
|
1
|
-
function _define_property(obj, key, value) {
|
|
2
|
-
if (key in obj) {
|
|
3
|
-
Object.defineProperty(obj, key, {
|
|
4
|
-
value: value,
|
|
5
|
-
enumerable: true,
|
|
6
|
-
configurable: true,
|
|
7
|
-
writable: true
|
|
8
|
-
});
|
|
9
|
-
} else {
|
|
10
|
-
obj[key] = value;
|
|
11
|
-
}
|
|
12
|
-
return obj;
|
|
13
|
-
}
|
|
14
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
15
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
16
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
17
|
-
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
18
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
19
|
-
}
|
|
20
|
-
function _ts_metadata(k, v) {
|
|
21
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
22
|
-
}
|
|
23
|
-
function _ts_param(paramIndex, decorator) {
|
|
24
|
-
return function(target, key) {
|
|
25
|
-
decorator(target, key, paramIndex);
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
import { createApiController, FORM_RESULT_PERMISSIONS } from '@flusys/nestjs-shared/classes';
|
|
29
|
-
import { CurrentUser, Public, RequirePermission } from '@flusys/nestjs-shared/decorators';
|
|
30
|
-
import { JwtAuthGuard, PermissionGuard } from '@flusys/nestjs-shared/guards';
|
|
31
|
-
import { ILoggedUserInfo } from '@flusys/nestjs-shared/interfaces';
|
|
32
|
-
import { Body, Controller, HttpCode, HttpStatus, Inject, Post, UseGuards } from '@nestjs/common';
|
|
33
|
-
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
|
|
34
|
-
import { FORM_RESULT_MESSAGES } from '../config';
|
|
35
|
-
import { CreateFormResultDto, FormResultResponseDto, GetMyDraftDto, GetResultsByFormDto, SubmitFormDto, UpdateDraftDto, UpdateFormResultDto } from '../dtos';
|
|
36
|
-
import { FormResultService } from '../services/form-result.service';
|
|
37
|
-
export class FormResultController extends createApiController(CreateFormResultDto, UpdateFormResultDto, FormResultResponseDto, {
|
|
38
|
-
entityName: 'form.result',
|
|
39
|
-
security: {
|
|
40
|
-
insert: {
|
|
41
|
-
level: 'permission',
|
|
42
|
-
permissions: [
|
|
43
|
-
FORM_RESULT_PERMISSIONS.CREATE
|
|
44
|
-
]
|
|
45
|
-
},
|
|
46
|
-
insertMany: {
|
|
47
|
-
level: 'permission',
|
|
48
|
-
permissions: [
|
|
49
|
-
FORM_RESULT_PERMISSIONS.CREATE
|
|
50
|
-
]
|
|
51
|
-
},
|
|
52
|
-
getById: {
|
|
53
|
-
level: 'permission',
|
|
54
|
-
permissions: [
|
|
55
|
-
FORM_RESULT_PERMISSIONS.READ
|
|
56
|
-
]
|
|
57
|
-
},
|
|
58
|
-
getAll: {
|
|
59
|
-
level: 'permission',
|
|
60
|
-
permissions: [
|
|
61
|
-
FORM_RESULT_PERMISSIONS.READ
|
|
62
|
-
]
|
|
63
|
-
},
|
|
64
|
-
update: {
|
|
65
|
-
level: 'permission',
|
|
66
|
-
permissions: [
|
|
67
|
-
FORM_RESULT_PERMISSIONS.UPDATE
|
|
68
|
-
]
|
|
69
|
-
},
|
|
70
|
-
updateMany: {
|
|
71
|
-
level: 'permission',
|
|
72
|
-
permissions: [
|
|
73
|
-
FORM_RESULT_PERMISSIONS.UPDATE
|
|
74
|
-
]
|
|
75
|
-
},
|
|
76
|
-
delete: {
|
|
77
|
-
level: 'permission',
|
|
78
|
-
permissions: [
|
|
79
|
-
FORM_RESULT_PERMISSIONS.DELETE
|
|
80
|
-
]
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}) {
|
|
84
|
-
// Submit Endpoints
|
|
85
|
-
/**
|
|
86
|
-
* Submit form with authentication
|
|
87
|
-
*/ async submitForm(dto, user) {
|
|
88
|
-
const data = await this.formResultService.submitForm(dto, user, false);
|
|
89
|
-
return {
|
|
90
|
-
success: true,
|
|
91
|
-
message: 'Form submitted successfully',
|
|
92
|
-
messageKey: FORM_RESULT_MESSAGES.SUBMIT_SUCCESS,
|
|
93
|
-
data
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
async submitPublicForm(dto) {
|
|
97
|
-
const data = await this.formResultService.submitForm(dto, null, true);
|
|
98
|
-
return {
|
|
99
|
-
success: true,
|
|
100
|
-
message: 'Form submitted successfully',
|
|
101
|
-
messageKey: FORM_RESULT_MESSAGES.SUBMIT_SUCCESS,
|
|
102
|
-
data
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
// Draft Endpoints
|
|
106
|
-
async getMyDraft(dto, user) {
|
|
107
|
-
const data = await this.formResultService.getMyDraft(dto.formId, user);
|
|
108
|
-
return {
|
|
109
|
-
success: true,
|
|
110
|
-
message: 'Draft retrieved',
|
|
111
|
-
messageKey: FORM_RESULT_MESSAGES.DRAFT_GET_SUCCESS,
|
|
112
|
-
data
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
async updateDraft(dto, user) {
|
|
116
|
-
const data = await this.formResultService.updateDraft(dto.draftId, dto, user);
|
|
117
|
-
return {
|
|
118
|
-
success: true,
|
|
119
|
-
message: 'Draft updated successfully',
|
|
120
|
-
messageKey: FORM_RESULT_MESSAGES.DRAFT_UPDATE_SUCCESS,
|
|
121
|
-
data
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
// Query Endpoints
|
|
125
|
-
/**
|
|
126
|
-
* Get results by form ID with pagination
|
|
127
|
-
*/ async getByFormId(dto, user) {
|
|
128
|
-
const page = dto.page ?? 0;
|
|
129
|
-
const pageSize = dto.pageSize ?? 10;
|
|
130
|
-
const result = await this.formResultService.getByFormId(dto.formId, user, {
|
|
131
|
-
page,
|
|
132
|
-
pageSize
|
|
133
|
-
});
|
|
134
|
-
return {
|
|
135
|
-
success: true,
|
|
136
|
-
message: 'Form results retrieved successfully',
|
|
137
|
-
messageKey: FORM_RESULT_MESSAGES.GET_ALL_SUCCESS,
|
|
138
|
-
data: result.data,
|
|
139
|
-
meta: {
|
|
140
|
-
total: result.total,
|
|
141
|
-
page,
|
|
142
|
-
pageSize,
|
|
143
|
-
count: result.data.length
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* Check if current user has already submitted this form (non-draft)
|
|
149
|
-
* Used for single response mode
|
|
150
|
-
*/ async hasUserSubmitted(dto, user) {
|
|
151
|
-
const hasSubmitted = await this.formResultService.hasUserSubmitted(dto.formId, user);
|
|
152
|
-
return {
|
|
153
|
-
success: true,
|
|
154
|
-
message: hasSubmitted ? 'User has submitted this form' : 'User has not submitted this form',
|
|
155
|
-
messageKey: hasSubmitted ? FORM_RESULT_MESSAGES.HAS_SUBMITTED_SUCCESS : FORM_RESULT_MESSAGES.HAS_NOT_SUBMITTED_SUCCESS,
|
|
156
|
-
data: hasSubmitted
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
constructor(formResultService){
|
|
160
|
-
super(formResultService), _define_property(this, "formResultService", void 0), this.formResultService = formResultService;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
_ts_decorate([
|
|
164
|
-
Post('submit'),
|
|
165
|
-
UseGuards(JwtAuthGuard),
|
|
166
|
-
ApiBearerAuth(),
|
|
167
|
-
HttpCode(HttpStatus.CREATED),
|
|
168
|
-
ApiOperation({
|
|
169
|
-
summary: 'Submit form result (authenticated)'
|
|
170
|
-
}),
|
|
171
|
-
_ts_param(0, Body()),
|
|
172
|
-
_ts_param(1, CurrentUser()),
|
|
173
|
-
_ts_metadata("design:type", Function),
|
|
174
|
-
_ts_metadata("design:paramtypes", [
|
|
175
|
-
typeof SubmitFormDto === "undefined" ? Object : SubmitFormDto,
|
|
176
|
-
typeof ILoggedUserInfo === "undefined" ? Object : ILoggedUserInfo
|
|
177
|
-
]),
|
|
178
|
-
_ts_metadata("design:returntype", Promise)
|
|
179
|
-
], FormResultController.prototype, "submitForm", null);
|
|
180
|
-
_ts_decorate([
|
|
181
|
-
Post('submit-public'),
|
|
182
|
-
Public(),
|
|
183
|
-
HttpCode(HttpStatus.CREATED),
|
|
184
|
-
ApiOperation({
|
|
185
|
-
summary: 'Submit public form (no auth required)'
|
|
186
|
-
}),
|
|
187
|
-
_ts_param(0, Body()),
|
|
188
|
-
_ts_metadata("design:type", Function),
|
|
189
|
-
_ts_metadata("design:paramtypes", [
|
|
190
|
-
typeof SubmitFormDto === "undefined" ? Object : SubmitFormDto
|
|
191
|
-
]),
|
|
192
|
-
_ts_metadata("design:returntype", Promise)
|
|
193
|
-
], FormResultController.prototype, "submitPublicForm", null);
|
|
194
|
-
_ts_decorate([
|
|
195
|
-
Post('my-draft'),
|
|
196
|
-
UseGuards(JwtAuthGuard),
|
|
197
|
-
ApiBearerAuth(),
|
|
198
|
-
HttpCode(HttpStatus.OK),
|
|
199
|
-
ApiOperation({
|
|
200
|
-
summary: 'Get my draft for a form'
|
|
201
|
-
}),
|
|
202
|
-
_ts_param(0, Body()),
|
|
203
|
-
_ts_param(1, CurrentUser()),
|
|
204
|
-
_ts_metadata("design:type", Function),
|
|
205
|
-
_ts_metadata("design:paramtypes", [
|
|
206
|
-
typeof GetMyDraftDto === "undefined" ? Object : GetMyDraftDto,
|
|
207
|
-
typeof ILoggedUserInfo === "undefined" ? Object : ILoggedUserInfo
|
|
208
|
-
]),
|
|
209
|
-
_ts_metadata("design:returntype", Promise)
|
|
210
|
-
], FormResultController.prototype, "getMyDraft", null);
|
|
211
|
-
_ts_decorate([
|
|
212
|
-
Post('update-draft'),
|
|
213
|
-
UseGuards(JwtAuthGuard),
|
|
214
|
-
ApiBearerAuth(),
|
|
215
|
-
HttpCode(HttpStatus.OK),
|
|
216
|
-
ApiOperation({
|
|
217
|
-
summary: 'Update existing draft'
|
|
218
|
-
}),
|
|
219
|
-
_ts_param(0, Body()),
|
|
220
|
-
_ts_param(1, CurrentUser()),
|
|
221
|
-
_ts_metadata("design:type", Function),
|
|
222
|
-
_ts_metadata("design:paramtypes", [
|
|
223
|
-
typeof UpdateDraftDto === "undefined" ? Object : UpdateDraftDto,
|
|
224
|
-
typeof ILoggedUserInfo === "undefined" ? Object : ILoggedUserInfo
|
|
225
|
-
]),
|
|
226
|
-
_ts_metadata("design:returntype", Promise)
|
|
227
|
-
], FormResultController.prototype, "updateDraft", null);
|
|
228
|
-
_ts_decorate([
|
|
229
|
-
Post('by-form'),
|
|
230
|
-
UseGuards(JwtAuthGuard, PermissionGuard),
|
|
231
|
-
ApiBearerAuth(),
|
|
232
|
-
RequirePermission(FORM_RESULT_PERMISSIONS.READ),
|
|
233
|
-
HttpCode(HttpStatus.OK),
|
|
234
|
-
ApiOperation({
|
|
235
|
-
summary: 'Get results by form ID'
|
|
236
|
-
}),
|
|
237
|
-
_ts_param(0, Body()),
|
|
238
|
-
_ts_param(1, CurrentUser()),
|
|
239
|
-
_ts_metadata("design:type", Function),
|
|
240
|
-
_ts_metadata("design:paramtypes", [
|
|
241
|
-
typeof GetResultsByFormDto === "undefined" ? Object : GetResultsByFormDto,
|
|
242
|
-
typeof ILoggedUserInfo === "undefined" ? Object : ILoggedUserInfo
|
|
243
|
-
]),
|
|
244
|
-
_ts_metadata("design:returntype", Promise)
|
|
245
|
-
], FormResultController.prototype, "getByFormId", null);
|
|
246
|
-
_ts_decorate([
|
|
247
|
-
Post('has-submitted'),
|
|
248
|
-
UseGuards(JwtAuthGuard),
|
|
249
|
-
ApiBearerAuth(),
|
|
250
|
-
HttpCode(HttpStatus.OK),
|
|
251
|
-
ApiOperation({
|
|
252
|
-
summary: 'Check if user has submitted form'
|
|
253
|
-
}),
|
|
254
|
-
_ts_param(0, Body()),
|
|
255
|
-
_ts_param(1, CurrentUser()),
|
|
256
|
-
_ts_metadata("design:type", Function),
|
|
257
|
-
_ts_metadata("design:paramtypes", [
|
|
258
|
-
typeof GetMyDraftDto === "undefined" ? Object : GetMyDraftDto,
|
|
259
|
-
typeof ILoggedUserInfo === "undefined" ? Object : ILoggedUserInfo
|
|
260
|
-
]),
|
|
261
|
-
_ts_metadata("design:returntype", Promise)
|
|
262
|
-
], FormResultController.prototype, "hasUserSubmitted", null);
|
|
263
|
-
FormResultController = _ts_decorate([
|
|
264
|
-
ApiTags('Form Builder - Results'),
|
|
265
|
-
Controller('form-builder/result'),
|
|
266
|
-
_ts_param(0, Inject(FormResultService)),
|
|
267
|
-
_ts_metadata("design:type", Function),
|
|
268
|
-
_ts_metadata("design:paramtypes", [
|
|
269
|
-
typeof FormResultService === "undefined" ? Object : FormResultService
|
|
270
|
-
])
|
|
271
|
-
], FormResultController);
|