oca-shared-model 1.0.11 → 1.0.13
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/helper/base-service.d.ts +8 -2
- package/dist/helper/base-service.js +28 -0
- package/dist/helper/pagination-filter.d.ts +7 -0
- package/dist/helper/pagination-filter.js +6 -0
- package/dist/library/master_answers/entities/master_answer.entity.d.ts +2 -0
- package/dist/library/master_answers/entities/master_answer.entity.js +6 -0
- package/dist/library/master_questions/entities/master_question.entity.d.ts +3 -0
- package/dist/library/master_questions/entities/master_question.entity.js +9 -0
- package/dist/library/master_questions/master_questions.service.d.ts +2 -12
- package/dist/library/master_questions/master_questions.service.js +3 -104
- package/package.json +2 -1
|
@@ -1,14 +1,20 @@
|
|
|
1
|
-
import { Repository } from "typeorm";
|
|
1
|
+
import { DeepPartial, Repository } from "typeorm";
|
|
2
2
|
import { OptionFilter } from "./option-filter";
|
|
3
3
|
import { BaseEntity } from "./base-entity";
|
|
4
|
+
import { PaginationFilter } from "./pagination-filter";
|
|
4
5
|
export declare class BaseService<T extends BaseEntity> {
|
|
5
6
|
protected readonly repository: Repository<T>;
|
|
6
7
|
constructor(repository: Repository<T>);
|
|
7
|
-
create(payload:
|
|
8
|
+
create(payload: DeepPartial<T>): Promise<T>;
|
|
8
9
|
findAll(): Promise<T[]>;
|
|
9
10
|
findOne(id: number): Promise<T | undefined>;
|
|
10
11
|
update(id: number, payload: any): Promise<any>;
|
|
11
12
|
remove(id: number): Promise<void>;
|
|
12
13
|
findByOption(filter: OptionFilter): Promise<T[] | undefined>;
|
|
13
14
|
findOneByOption(filter: OptionFilter): Promise<T | null | undefined>;
|
|
15
|
+
findPaginate(filter: PaginationFilter): Promise<{
|
|
16
|
+
data: T[];
|
|
17
|
+
total: number;
|
|
18
|
+
total_pages: number;
|
|
19
|
+
} | undefined>;
|
|
14
20
|
}
|
|
@@ -122,6 +122,34 @@ let BaseService = class BaseService {
|
|
|
122
122
|
}
|
|
123
123
|
});
|
|
124
124
|
}
|
|
125
|
+
findPaginate(filter) {
|
|
126
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
127
|
+
try {
|
|
128
|
+
let { page, size, where, relations, order } = filter;
|
|
129
|
+
if (page === 0 || page === undefined)
|
|
130
|
+
page = 1;
|
|
131
|
+
const offset = page * size;
|
|
132
|
+
const [data, total] = yield this.repository.findAndCount({
|
|
133
|
+
where: where,
|
|
134
|
+
relations: relations,
|
|
135
|
+
order: order,
|
|
136
|
+
take: size,
|
|
137
|
+
skip: offset,
|
|
138
|
+
});
|
|
139
|
+
const totalPages = Math.ceil(total / size);
|
|
140
|
+
return {
|
|
141
|
+
data: data,
|
|
142
|
+
total: total,
|
|
143
|
+
total_pages: totalPages,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
if (error instanceof Error) {
|
|
148
|
+
throw new common_1.InternalServerErrorException(error.message);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
}
|
|
125
153
|
};
|
|
126
154
|
exports.BaseService = BaseService;
|
|
127
155
|
exports.BaseService = BaseService = __decorate([
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { DefaultColumn } from "../../../helper/default-column";
|
|
2
|
+
import { MasterQuestion } from "../../master_questions/entities/master_question.entity";
|
|
2
3
|
export declare class MasterAnswer extends DefaultColumn {
|
|
3
4
|
id?: number;
|
|
4
5
|
question_id?: string;
|
|
5
6
|
answer?: string;
|
|
6
7
|
correct?: boolean;
|
|
8
|
+
question?: MasterQuestion;
|
|
7
9
|
}
|
|
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.MasterAnswer = void 0;
|
|
13
13
|
const typeorm_1 = require("typeorm");
|
|
14
14
|
const default_column_1 = require("../../../helper/default-column");
|
|
15
|
+
const master_question_entity_1 = require("../../master_questions/entities/master_question.entity");
|
|
15
16
|
let MasterAnswer = class MasterAnswer extends default_column_1.DefaultColumn {
|
|
16
17
|
};
|
|
17
18
|
exports.MasterAnswer = MasterAnswer;
|
|
@@ -31,6 +32,11 @@ __decorate([
|
|
|
31
32
|
(0, typeorm_1.Column)(),
|
|
32
33
|
__metadata("design:type", Boolean)
|
|
33
34
|
], MasterAnswer.prototype, "correct", void 0);
|
|
35
|
+
__decorate([
|
|
36
|
+
(0, typeorm_1.ManyToOne)(() => master_question_entity_1.MasterQuestion, (q) => q.answers),
|
|
37
|
+
(0, typeorm_1.JoinColumn)({ name: "question_id", referencedColumnName: "id" }),
|
|
38
|
+
__metadata("design:type", master_question_entity_1.MasterQuestion)
|
|
39
|
+
], MasterAnswer.prototype, "question", void 0);
|
|
34
40
|
exports.MasterAnswer = MasterAnswer = __decorate([
|
|
35
41
|
(0, typeorm_1.Entity)({
|
|
36
42
|
schema: "library",
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { DefaultColumn } from "../../../helper/default-column";
|
|
2
|
+
import { MasterAnswer } from "../../master_answers/entities/master_answer.entity";
|
|
2
3
|
export declare class MasterQuestion extends DefaultColumn {
|
|
3
4
|
id?: number;
|
|
4
5
|
question?: string;
|
|
6
|
+
type?: string;
|
|
5
7
|
image_url?: string;
|
|
6
8
|
rank?: string;
|
|
7
9
|
vessel_type?: string;
|
|
10
|
+
answers?: MasterAnswer[];
|
|
8
11
|
}
|
|
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.MasterQuestion = void 0;
|
|
13
13
|
const typeorm_1 = require("typeorm");
|
|
14
14
|
const default_column_1 = require("../../../helper/default-column");
|
|
15
|
+
const master_answer_entity_1 = require("../../master_answers/entities/master_answer.entity");
|
|
15
16
|
let MasterQuestion = class MasterQuestion extends default_column_1.DefaultColumn {
|
|
16
17
|
};
|
|
17
18
|
exports.MasterQuestion = MasterQuestion;
|
|
@@ -23,6 +24,10 @@ __decorate([
|
|
|
23
24
|
(0, typeorm_1.Column)(),
|
|
24
25
|
__metadata("design:type", String)
|
|
25
26
|
], MasterQuestion.prototype, "question", void 0);
|
|
27
|
+
__decorate([
|
|
28
|
+
(0, typeorm_1.Column)(),
|
|
29
|
+
__metadata("design:type", String)
|
|
30
|
+
], MasterQuestion.prototype, "type", void 0);
|
|
26
31
|
__decorate([
|
|
27
32
|
(0, typeorm_1.Column)(),
|
|
28
33
|
__metadata("design:type", String)
|
|
@@ -35,6 +40,10 @@ __decorate([
|
|
|
35
40
|
(0, typeorm_1.Column)({ array: true }),
|
|
36
41
|
__metadata("design:type", String)
|
|
37
42
|
], MasterQuestion.prototype, "vessel_type", void 0);
|
|
43
|
+
__decorate([
|
|
44
|
+
(0, typeorm_1.OneToMany)(() => master_answer_entity_1.MasterAnswer, (q) => q.question),
|
|
45
|
+
__metadata("design:type", Array)
|
|
46
|
+
], MasterQuestion.prototype, "answers", void 0);
|
|
38
47
|
exports.MasterQuestion = MasterQuestion = __decorate([
|
|
39
48
|
(0, typeorm_1.Entity)({ schema: "library", name: "master_questions" })
|
|
40
49
|
], MasterQuestion);
|
|
@@ -1,16 +1,6 @@
|
|
|
1
|
-
import { CreateMasterQuestionDto } from "./dto/create-master_question.dto";
|
|
2
|
-
import { UpdateMasterQuestionDto } from "./dto/update-master_question.dto";
|
|
3
1
|
import { MasterQuestion } from "./entities/master_question.entity";
|
|
4
2
|
import { Repository } from "typeorm";
|
|
5
|
-
import {
|
|
6
|
-
export declare class MasterQuestionsService {
|
|
7
|
-
private readonly repository;
|
|
3
|
+
import { BaseService } from "../../helper/base-service";
|
|
4
|
+
export declare class MasterQuestionsService extends BaseService<MasterQuestion> {
|
|
8
5
|
constructor(repository: Repository<MasterQuestion>);
|
|
9
|
-
create(payload: CreateMasterQuestionDto): Promise<MasterQuestion>;
|
|
10
|
-
findAll(): Promise<MasterQuestion[]>;
|
|
11
|
-
findOne(id: number): Promise<MasterQuestion | undefined>;
|
|
12
|
-
update(id: number, payload: UpdateMasterQuestionDto): Promise<(MasterQuestion & UpdateMasterQuestionDto) | undefined>;
|
|
13
|
-
remove(id: number): Promise<import("typeorm").DeleteResult>;
|
|
14
|
-
findByOption(filter: OptionFilter): Promise<MasterQuestion[] | undefined>;
|
|
15
|
-
findOneByOption(filter: OptionFilter): Promise<MasterQuestion | null | undefined>;
|
|
16
6
|
}
|
|
@@ -11,117 +11,16 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
11
11
|
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
12
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
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
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
15
|
exports.MasterQuestionsService = void 0;
|
|
25
16
|
const common_1 = require("@nestjs/common");
|
|
26
17
|
const typeorm_1 = require("@nestjs/typeorm");
|
|
27
18
|
const master_question_entity_1 = require("./entities/master_question.entity");
|
|
28
19
|
const typeorm_2 = require("typeorm");
|
|
29
|
-
|
|
20
|
+
const base_service_1 = require("../../helper/base-service");
|
|
21
|
+
let MasterQuestionsService = class MasterQuestionsService extends base_service_1.BaseService {
|
|
30
22
|
constructor(repository) {
|
|
31
|
-
|
|
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(`MasterQuestion with ID ${id} not found`);
|
|
61
|
-
}
|
|
62
|
-
return result;
|
|
63
|
-
}
|
|
64
|
-
catch (error) { }
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
update(id, payload) {
|
|
68
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
-
try {
|
|
70
|
-
const data = yield this.findOne(id);
|
|
71
|
-
if (!data) {
|
|
72
|
-
throw new common_1.NotFoundException(`MasterQuestion with ID ${id} not found`);
|
|
73
|
-
}
|
|
74
|
-
const update = Object.assign(data, payload);
|
|
75
|
-
const result = yield this.repository.save(update);
|
|
76
|
-
return result;
|
|
77
|
-
}
|
|
78
|
-
catch (error) {
|
|
79
|
-
if (error instanceof Error) {
|
|
80
|
-
throw new common_1.InternalServerErrorException(error.message);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
remove(id) {
|
|
86
|
-
return this.repository.delete(id);
|
|
87
|
-
}
|
|
88
|
-
findByOption(filter) {
|
|
89
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
90
|
-
try {
|
|
91
|
-
const { select, where, relations, order } = filter;
|
|
92
|
-
const result = yield this.repository.find({
|
|
93
|
-
select: select,
|
|
94
|
-
where: where,
|
|
95
|
-
relations: relations,
|
|
96
|
-
order: order,
|
|
97
|
-
});
|
|
98
|
-
return result;
|
|
99
|
-
}
|
|
100
|
-
catch (error) {
|
|
101
|
-
if (error instanceof Error) {
|
|
102
|
-
throw new common_1.InternalServerErrorException(error.message);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
findOneByOption(filter) {
|
|
108
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
109
|
-
try {
|
|
110
|
-
const { select, where, relations, order } = filter;
|
|
111
|
-
const result = yield this.repository.findOne({
|
|
112
|
-
select: select,
|
|
113
|
-
where: where,
|
|
114
|
-
relations: relations,
|
|
115
|
-
order: order,
|
|
116
|
-
});
|
|
117
|
-
return result;
|
|
118
|
-
}
|
|
119
|
-
catch (error) {
|
|
120
|
-
if (error instanceof Error) {
|
|
121
|
-
throw new common_1.InternalServerErrorException(error.message);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
});
|
|
23
|
+
super(repository);
|
|
125
24
|
}
|
|
126
25
|
};
|
|
127
26
|
exports.MasterQuestionsService = MasterQuestionsService;
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oca-shared-model",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.13",
|
|
4
4
|
"description": "onboard shared model",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "nest build",
|
|
8
8
|
"clean": "rm -rf dist",
|
|
9
9
|
"predeploy": "npm run clean && npm version patch && npm run build",
|
|
10
|
+
"deploy": "npm publish",
|
|
10
11
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
11
12
|
},
|
|
12
13
|
"author": "DONO",
|