oca-shared-model 1.0.2 → 1.0.4
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/library/library.module.js +2 -1
- package/dist/library/master_answers/dto/create-master_answer.dto.d.ts +2 -0
- package/dist/library/master_answers/dto/create-master_answer.dto.js +6 -0
- package/dist/library/master_answers/dto/update-master_answer.dto.d.ts +5 -0
- package/dist/library/master_answers/dto/update-master_answer.dto.js +8 -0
- package/dist/library/master_answers/entities/master_answer.entity.d.ts +7 -0
- package/dist/library/master_answers/entities/master_answer.entity.js +39 -0
- package/dist/library/master_answers/master_answers.module.d.ts +2 -0
- package/dist/library/master_answers/master_answers.module.js +20 -0
- package/dist/library/master_answers/master_answers.service.d.ts +16 -0
- package/dist/library/master_answers/master_answers.service.js +136 -0
- package/dist/library/master_questions/master_questions.service.d.ts +5 -5
- package/dist/library/master_questions/master_questions.service.js +16 -4
- package/package.json +2 -2
- package/src/library/library.module.ts +2 -1
- package/src/library/master_answers/dto/create-master_answer.dto.ts +1 -0
- package/src/library/master_answers/dto/update-master_answer.dto.ts +4 -0
- package/src/library/master_answers/entities/master_answer.entity.ts +17 -0
- package/src/library/master_answers/master_answers.module.ts +11 -0
- package/src/library/master_answers/master_answers.service.spec.ts +18 -0
- package/src/library/master_answers/master_answers.service.ts +108 -0
- package/src/library/master_questions/master_questions.service.ts +24 -12
|
@@ -9,12 +9,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.LibraryModule = void 0;
|
|
10
10
|
const common_1 = require("@nestjs/common");
|
|
11
11
|
const master_questions_module_1 = require("./master_questions/master_questions.module");
|
|
12
|
+
const master_answers_module_1 = require("./master_answers/master_answers.module");
|
|
12
13
|
let LibraryModule = class LibraryModule {
|
|
13
14
|
};
|
|
14
15
|
exports.LibraryModule = LibraryModule;
|
|
15
16
|
exports.LibraryModule = LibraryModule = __decorate([
|
|
16
17
|
(0, common_1.Module)({
|
|
17
|
-
imports: [master_questions_module_1.MasterQuestionsModule],
|
|
18
|
+
imports: [master_questions_module_1.MasterQuestionsModule, master_answers_module_1.MasterAnswersModule],
|
|
18
19
|
exports: [master_questions_module_1.MasterQuestionsModule],
|
|
19
20
|
})
|
|
20
21
|
], LibraryModule);
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { CreateMasterAnswerDto } from './create-master_answer.dto';
|
|
2
|
+
declare const UpdateMasterAnswerDto_base: import("@nestjs/mapped-types").MappedType<Partial<CreateMasterAnswerDto>>;
|
|
3
|
+
export declare class UpdateMasterAnswerDto extends UpdateMasterAnswerDto_base {
|
|
4
|
+
}
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UpdateMasterAnswerDto = void 0;
|
|
4
|
+
const mapped_types_1 = require("@nestjs/mapped-types");
|
|
5
|
+
const create_master_answer_dto_1 = require("./create-master_answer.dto");
|
|
6
|
+
class UpdateMasterAnswerDto extends (0, mapped_types_1.PartialType)(create_master_answer_dto_1.CreateMasterAnswerDto) {
|
|
7
|
+
}
|
|
8
|
+
exports.UpdateMasterAnswerDto = UpdateMasterAnswerDto;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.MasterAnswer = void 0;
|
|
13
|
+
const typeorm_1 = require("typeorm");
|
|
14
|
+
const default_column_1 = require("../../../helper/default-column");
|
|
15
|
+
let MasterAnswer = class MasterAnswer extends default_column_1.DefaultColumn {
|
|
16
|
+
};
|
|
17
|
+
exports.MasterAnswer = MasterAnswer;
|
|
18
|
+
__decorate([
|
|
19
|
+
(0, typeorm_1.PrimaryGeneratedColumn)(),
|
|
20
|
+
__metadata("design:type", Number)
|
|
21
|
+
], MasterAnswer.prototype, "id", void 0);
|
|
22
|
+
__decorate([
|
|
23
|
+
(0, typeorm_1.Column)(),
|
|
24
|
+
__metadata("design:type", String)
|
|
25
|
+
], MasterAnswer.prototype, "question_id", void 0);
|
|
26
|
+
__decorate([
|
|
27
|
+
(0, typeorm_1.Column)(),
|
|
28
|
+
__metadata("design:type", String)
|
|
29
|
+
], MasterAnswer.prototype, "answer", void 0);
|
|
30
|
+
__decorate([
|
|
31
|
+
(0, typeorm_1.Column)(),
|
|
32
|
+
__metadata("design:type", Boolean)
|
|
33
|
+
], MasterAnswer.prototype, "correct", void 0);
|
|
34
|
+
exports.MasterAnswer = MasterAnswer = __decorate([
|
|
35
|
+
(0, typeorm_1.Entity)({
|
|
36
|
+
schema: "library",
|
|
37
|
+
name: "master_answers",
|
|
38
|
+
})
|
|
39
|
+
], MasterAnswer);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.MasterAnswersModule = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const master_answers_service_1 = require("./master_answers.service");
|
|
12
|
+
let MasterAnswersModule = class MasterAnswersModule {
|
|
13
|
+
};
|
|
14
|
+
exports.MasterAnswersModule = MasterAnswersModule;
|
|
15
|
+
exports.MasterAnswersModule = MasterAnswersModule = __decorate([
|
|
16
|
+
(0, common_1.Module)({
|
|
17
|
+
providers: [master_answers_service_1.MasterAnswersService],
|
|
18
|
+
exports: [master_answers_service_1.MasterAnswersService],
|
|
19
|
+
})
|
|
20
|
+
], MasterAnswersModule);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { CreateMasterAnswerDto } from "./dto/create-master_answer.dto";
|
|
2
|
+
import { UpdateMasterAnswerDto } from "./dto/update-master_answer.dto";
|
|
3
|
+
import { MasterAnswer } from "./entities/master_answer.entity";
|
|
4
|
+
import { Repository } from "typeorm";
|
|
5
|
+
import { OptionFilter } from "../../helper/option-filter";
|
|
6
|
+
export declare class MasterAnswersService {
|
|
7
|
+
private readonly repository;
|
|
8
|
+
constructor(repository: Repository<MasterAnswer>);
|
|
9
|
+
create(payload: CreateMasterAnswerDto): Promise<MasterAnswer>;
|
|
10
|
+
findAll(): Promise<MasterAnswer[]>;
|
|
11
|
+
findOne(id: number): Promise<MasterAnswer | undefined>;
|
|
12
|
+
update(id: number, payload: UpdateMasterAnswerDto): Promise<(MasterAnswer & UpdateMasterAnswerDto) | undefined>;
|
|
13
|
+
remove(id: number): string;
|
|
14
|
+
findByOption(filter: OptionFilter): Promise<MasterAnswer[] | undefined>;
|
|
15
|
+
findOneByOption(filter: OptionFilter): Promise<MasterAnswer | null | undefined>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
15
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
16
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
17
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
18
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
19
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
20
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.MasterAnswersService = void 0;
|
|
25
|
+
const common_1 = require("@nestjs/common");
|
|
26
|
+
const typeorm_1 = require("@nestjs/typeorm");
|
|
27
|
+
const master_answer_entity_1 = require("./entities/master_answer.entity");
|
|
28
|
+
const typeorm_2 = require("typeorm");
|
|
29
|
+
let MasterAnswersService = class MasterAnswersService {
|
|
30
|
+
constructor(repository) {
|
|
31
|
+
this.repository = repository;
|
|
32
|
+
}
|
|
33
|
+
create(payload) {
|
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
try {
|
|
36
|
+
const data = this.repository.create(payload);
|
|
37
|
+
const result = yield this.repository.save(data);
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
if (error instanceof Error) {
|
|
42
|
+
throw new common_1.InternalServerErrorException(error.message);
|
|
43
|
+
}
|
|
44
|
+
throw new common_1.InternalServerErrorException("An unknown error occurred");
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
findAll() {
|
|
49
|
+
return this.repository.find();
|
|
50
|
+
}
|
|
51
|
+
findOne(id) {
|
|
52
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
try {
|
|
54
|
+
const result = yield this.repository.findOne({
|
|
55
|
+
where: {
|
|
56
|
+
id: id,
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
if (!result) {
|
|
60
|
+
throw new common_1.NotFoundException(`answer with ID ${id} not found`);
|
|
61
|
+
}
|
|
62
|
+
return result;
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
if (error instanceof Error) {
|
|
66
|
+
throw new common_1.InternalServerErrorException(error.message);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
update(id, payload) {
|
|
72
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
try {
|
|
74
|
+
const data = yield this.findOne(id);
|
|
75
|
+
if (!data) {
|
|
76
|
+
throw new common_1.NotFoundException(`MasterQuestion with ID ${id} not found`);
|
|
77
|
+
}
|
|
78
|
+
const update = Object.assign(data, payload);
|
|
79
|
+
const result = yield this.repository.save(update);
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
if (error instanceof Error) {
|
|
84
|
+
throw new common_1.InternalServerErrorException(error.message);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
remove(id) {
|
|
90
|
+
return `This action removes a #${id} masterAnswer`;
|
|
91
|
+
}
|
|
92
|
+
findByOption(filter) {
|
|
93
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
try {
|
|
95
|
+
const { select, where, relations, order } = filter;
|
|
96
|
+
const result = yield this.repository.find({
|
|
97
|
+
select: select,
|
|
98
|
+
where: where,
|
|
99
|
+
relations: relations,
|
|
100
|
+
order: order,
|
|
101
|
+
});
|
|
102
|
+
return result;
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
if (error instanceof Error) {
|
|
106
|
+
throw new common_1.InternalServerErrorException(error.message);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
findOneByOption(filter) {
|
|
112
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
try {
|
|
114
|
+
const { select, where, relations, order } = filter;
|
|
115
|
+
const result = yield this.repository.findOne({
|
|
116
|
+
select: select,
|
|
117
|
+
where: where,
|
|
118
|
+
relations: relations,
|
|
119
|
+
order: order,
|
|
120
|
+
});
|
|
121
|
+
return result;
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
if (error instanceof Error) {
|
|
125
|
+
throw new common_1.InternalServerErrorException(error.message);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
exports.MasterAnswersService = MasterAnswersService;
|
|
132
|
+
exports.MasterAnswersService = MasterAnswersService = __decorate([
|
|
133
|
+
(0, common_1.Injectable)(),
|
|
134
|
+
__param(0, (0, typeorm_1.InjectRepository)(master_answer_entity_1.MasterAnswer)),
|
|
135
|
+
__metadata("design:paramtypes", [typeorm_2.Repository])
|
|
136
|
+
], MasterAnswersService);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { CreateMasterQuestionDto } from
|
|
2
|
-
import { UpdateMasterQuestionDto } from
|
|
3
|
-
import { MasterQuestion } from
|
|
4
|
-
import { Repository } from
|
|
5
|
-
import { OptionFilter } from
|
|
1
|
+
import { CreateMasterQuestionDto } from "./dto/create-master_question.dto";
|
|
2
|
+
import { UpdateMasterQuestionDto } from "./dto/update-master_question.dto";
|
|
3
|
+
import { MasterQuestion } from "./entities/master_question.entity";
|
|
4
|
+
import { Repository } from "typeorm";
|
|
5
|
+
import { OptionFilter } from "../../helper/option-filter";
|
|
6
6
|
export declare class MasterQuestionsService {
|
|
7
7
|
private readonly repository;
|
|
8
8
|
constructor(repository: Repository<MasterQuestion>);
|
|
@@ -41,7 +41,7 @@ let MasterQuestionsService = class MasterQuestionsService {
|
|
|
41
41
|
if (error instanceof Error) {
|
|
42
42
|
throw new common_1.InternalServerErrorException(error.message);
|
|
43
43
|
}
|
|
44
|
-
throw new common_1.InternalServerErrorException(
|
|
44
|
+
throw new common_1.InternalServerErrorException("An unknown error occurred");
|
|
45
45
|
}
|
|
46
46
|
});
|
|
47
47
|
}
|
|
@@ -75,7 +75,11 @@ let MasterQuestionsService = class MasterQuestionsService {
|
|
|
75
75
|
const result = yield this.repository.save(update);
|
|
76
76
|
return result;
|
|
77
77
|
}
|
|
78
|
-
catch (error) {
|
|
78
|
+
catch (error) {
|
|
79
|
+
if (error instanceof Error) {
|
|
80
|
+
throw new common_1.InternalServerErrorException(error.message);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
79
83
|
});
|
|
80
84
|
}
|
|
81
85
|
remove(id) {
|
|
@@ -93,7 +97,11 @@ let MasterQuestionsService = class MasterQuestionsService {
|
|
|
93
97
|
});
|
|
94
98
|
return result;
|
|
95
99
|
}
|
|
96
|
-
catch (error) {
|
|
100
|
+
catch (error) {
|
|
101
|
+
if (error instanceof Error) {
|
|
102
|
+
throw new common_1.InternalServerErrorException(error.message);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
97
105
|
});
|
|
98
106
|
}
|
|
99
107
|
findOneByOption(filter) {
|
|
@@ -108,7 +116,11 @@ let MasterQuestionsService = class MasterQuestionsService {
|
|
|
108
116
|
});
|
|
109
117
|
return result;
|
|
110
118
|
}
|
|
111
|
-
catch (error) {
|
|
119
|
+
catch (error) {
|
|
120
|
+
if (error instanceof Error) {
|
|
121
|
+
throw new common_1.InternalServerErrorException(error.message);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
112
124
|
});
|
|
113
125
|
}
|
|
114
126
|
};
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oca-shared-model",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "onboard shared model",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "nest build",
|
|
8
8
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
9
9
|
},
|
|
10
|
-
"author": "",
|
|
10
|
+
"author": "DONO",
|
|
11
11
|
"license": "ISC",
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@nestjs/common": "^10.3.10",
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Module } from '@nestjs/common';
|
|
2
2
|
import { MasterQuestionsModule } from './master_questions/master_questions.module';
|
|
3
|
+
import { MasterAnswersModule } from './master_answers/master_answers.module';
|
|
3
4
|
|
|
4
5
|
@Module({
|
|
5
|
-
imports: [MasterQuestionsModule],
|
|
6
|
+
imports: [MasterQuestionsModule, MasterAnswersModule],
|
|
6
7
|
exports: [MasterQuestionsModule],
|
|
7
8
|
})
|
|
8
9
|
export class LibraryModule {}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export class CreateMasterAnswerDto {}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Column, Entity, PrimaryGeneratedColumn } from "typeorm";
|
|
2
|
+
import { DefaultColumn } from "../../../helper/default-column";
|
|
3
|
+
|
|
4
|
+
@Entity({
|
|
5
|
+
schema: "library",
|
|
6
|
+
name: "master_answers",
|
|
7
|
+
})
|
|
8
|
+
export class MasterAnswer extends DefaultColumn {
|
|
9
|
+
@PrimaryGeneratedColumn()
|
|
10
|
+
id?: number;
|
|
11
|
+
@Column()
|
|
12
|
+
question_id?: string;
|
|
13
|
+
@Column()
|
|
14
|
+
answer?: string;
|
|
15
|
+
@Column()
|
|
16
|
+
correct?: boolean;
|
|
17
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Module } from "@nestjs/common";
|
|
2
|
+
import { MasterAnswersService } from "./master_answers.service";
|
|
3
|
+
import { TypeOrmModule } from "@nestjs/typeorm";
|
|
4
|
+
import { MasterAnswer } from "./entities/master_answer.entity";
|
|
5
|
+
|
|
6
|
+
@Module({
|
|
7
|
+
imports: [TypeOrmModule.forFeature([MasterAnswer])],
|
|
8
|
+
providers: [MasterAnswersService],
|
|
9
|
+
exports: [MasterAnswersService],
|
|
10
|
+
})
|
|
11
|
+
export class MasterAnswersModule {}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Test, TestingModule } from '@nestjs/testing';
|
|
2
|
+
import { MasterAnswersService } from './master_answers.service';
|
|
3
|
+
|
|
4
|
+
describe('MasterAnswersService', () => {
|
|
5
|
+
let service: MasterAnswersService;
|
|
6
|
+
|
|
7
|
+
beforeEach(async () => {
|
|
8
|
+
const module: TestingModule = await Test.createTestingModule({
|
|
9
|
+
providers: [MasterAnswersService],
|
|
10
|
+
}).compile();
|
|
11
|
+
|
|
12
|
+
service = module.get<MasterAnswersService>(MasterAnswersService);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('should be defined', () => {
|
|
16
|
+
expect(service).toBeDefined();
|
|
17
|
+
});
|
|
18
|
+
});
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Injectable,
|
|
3
|
+
InternalServerErrorException,
|
|
4
|
+
NotFoundException,
|
|
5
|
+
} from "@nestjs/common";
|
|
6
|
+
import { CreateMasterAnswerDto } from "./dto/create-master_answer.dto";
|
|
7
|
+
import { UpdateMasterAnswerDto } from "./dto/update-master_answer.dto";
|
|
8
|
+
import { InjectRepository } from "@nestjs/typeorm";
|
|
9
|
+
import { MasterAnswer } from "./entities/master_answer.entity";
|
|
10
|
+
import { Repository } from "typeorm";
|
|
11
|
+
import { OptionFilter } from "../../helper/option-filter";
|
|
12
|
+
|
|
13
|
+
@Injectable()
|
|
14
|
+
export class MasterAnswersService {
|
|
15
|
+
constructor(
|
|
16
|
+
@InjectRepository(MasterAnswer)
|
|
17
|
+
private readonly repository: Repository<MasterAnswer>
|
|
18
|
+
) {}
|
|
19
|
+
|
|
20
|
+
async create(payload: CreateMasterAnswerDto) {
|
|
21
|
+
try {
|
|
22
|
+
const data = this.repository.create(payload);
|
|
23
|
+
const result = await this.repository.save(data);
|
|
24
|
+
return result;
|
|
25
|
+
} catch (error) {
|
|
26
|
+
if (error instanceof Error) {
|
|
27
|
+
throw new InternalServerErrorException(error.message);
|
|
28
|
+
}
|
|
29
|
+
throw new InternalServerErrorException("An unknown error occurred");
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
findAll() {
|
|
34
|
+
return this.repository.find();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async findOne(id: number) {
|
|
38
|
+
try {
|
|
39
|
+
const result = await this.repository.findOne({
|
|
40
|
+
where: {
|
|
41
|
+
id: id,
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
if (!result) {
|
|
45
|
+
throw new NotFoundException(`answer with ID ${id} not found`);
|
|
46
|
+
}
|
|
47
|
+
return result;
|
|
48
|
+
} catch (error) {
|
|
49
|
+
if (error instanceof Error) {
|
|
50
|
+
throw new InternalServerErrorException(error.message);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async update(id: number, payload: UpdateMasterAnswerDto) {
|
|
56
|
+
try {
|
|
57
|
+
const data = await this.findOne(id);
|
|
58
|
+
if (!data) {
|
|
59
|
+
throw new NotFoundException(`MasterQuestion with ID ${id} not found`);
|
|
60
|
+
}
|
|
61
|
+
const update = Object.assign(data, payload);
|
|
62
|
+
const result = await this.repository.save(update);
|
|
63
|
+
return result;
|
|
64
|
+
} catch (error) {
|
|
65
|
+
if (error instanceof Error) {
|
|
66
|
+
throw new InternalServerErrorException(error.message);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
remove(id: number) {
|
|
72
|
+
return `This action removes a #${id} masterAnswer`;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async findByOption(filter: OptionFilter) {
|
|
76
|
+
try {
|
|
77
|
+
const { select, where, relations, order } = filter;
|
|
78
|
+
const result = await this.repository.find({
|
|
79
|
+
select: select,
|
|
80
|
+
where: where,
|
|
81
|
+
relations: relations,
|
|
82
|
+
order: order,
|
|
83
|
+
});
|
|
84
|
+
return result;
|
|
85
|
+
} catch (error) {
|
|
86
|
+
if (error instanceof Error) {
|
|
87
|
+
throw new InternalServerErrorException(error.message);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async findOneByOption(filter: OptionFilter) {
|
|
93
|
+
try {
|
|
94
|
+
const { select, where, relations, order } = filter;
|
|
95
|
+
const result = await this.repository.findOne({
|
|
96
|
+
select: select,
|
|
97
|
+
where: where,
|
|
98
|
+
relations: relations,
|
|
99
|
+
order: order,
|
|
100
|
+
});
|
|
101
|
+
return result;
|
|
102
|
+
} catch (error) {
|
|
103
|
+
if (error instanceof Error) {
|
|
104
|
+
throw new InternalServerErrorException(error.message);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
@@ -2,19 +2,19 @@ import {
|
|
|
2
2
|
Injectable,
|
|
3
3
|
InternalServerErrorException,
|
|
4
4
|
NotFoundException,
|
|
5
|
-
} from
|
|
6
|
-
import { CreateMasterQuestionDto } from
|
|
7
|
-
import { UpdateMasterQuestionDto } from
|
|
8
|
-
import { InjectRepository } from
|
|
9
|
-
import { MasterQuestion } from
|
|
10
|
-
import { Repository } from
|
|
11
|
-
import { OptionFilter } from
|
|
5
|
+
} from "@nestjs/common";
|
|
6
|
+
import { CreateMasterQuestionDto } from "./dto/create-master_question.dto";
|
|
7
|
+
import { UpdateMasterQuestionDto } from "./dto/update-master_question.dto";
|
|
8
|
+
import { InjectRepository } from "@nestjs/typeorm";
|
|
9
|
+
import { MasterQuestion } from "./entities/master_question.entity";
|
|
10
|
+
import { Repository } from "typeorm";
|
|
11
|
+
import { OptionFilter } from "../../helper/option-filter";
|
|
12
12
|
|
|
13
13
|
@Injectable()
|
|
14
14
|
export class MasterQuestionsService {
|
|
15
15
|
constructor(
|
|
16
16
|
@InjectRepository(MasterQuestion)
|
|
17
|
-
private readonly repository: Repository<MasterQuestion
|
|
17
|
+
private readonly repository: Repository<MasterQuestion>
|
|
18
18
|
) {}
|
|
19
19
|
|
|
20
20
|
async create(payload: CreateMasterQuestionDto) {
|
|
@@ -26,7 +26,7 @@ export class MasterQuestionsService {
|
|
|
26
26
|
if (error instanceof Error) {
|
|
27
27
|
throw new InternalServerErrorException(error.message);
|
|
28
28
|
}
|
|
29
|
-
throw new InternalServerErrorException(
|
|
29
|
+
throw new InternalServerErrorException("An unknown error occurred");
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
|
|
@@ -57,7 +57,11 @@ export class MasterQuestionsService {
|
|
|
57
57
|
const update = Object.assign(data, payload);
|
|
58
58
|
const result = await this.repository.save(update);
|
|
59
59
|
return result;
|
|
60
|
-
} catch (error) {
|
|
60
|
+
} catch (error) {
|
|
61
|
+
if (error instanceof Error) {
|
|
62
|
+
throw new InternalServerErrorException(error.message);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
61
65
|
}
|
|
62
66
|
|
|
63
67
|
remove(id: number) {
|
|
@@ -74,7 +78,11 @@ export class MasterQuestionsService {
|
|
|
74
78
|
order: order,
|
|
75
79
|
});
|
|
76
80
|
return result;
|
|
77
|
-
} catch (error) {
|
|
81
|
+
} catch (error) {
|
|
82
|
+
if (error instanceof Error) {
|
|
83
|
+
throw new InternalServerErrorException(error.message);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
78
86
|
}
|
|
79
87
|
|
|
80
88
|
async findOneByOption(filter: OptionFilter) {
|
|
@@ -87,6 +95,10 @@ export class MasterQuestionsService {
|
|
|
87
95
|
order: order,
|
|
88
96
|
});
|
|
89
97
|
return result;
|
|
90
|
-
} catch (error) {
|
|
98
|
+
} catch (error) {
|
|
99
|
+
if (error instanceof Error) {
|
|
100
|
+
throw new InternalServerErrorException(error.message);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
91
103
|
}
|
|
92
104
|
}
|