@hed-hog/faq 0.0.4 → 0.0.6
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/faq.controller.d.ts +66 -3
- package/dist/faq.controller.d.ts.map +1 -1
- package/dist/faq.service.d.ts +66 -3
- package/dist/faq.service.d.ts.map +1 -1
- package/dist/faq.service.js +74 -3
- package/dist/faq.service.js.map +1 -1
- package/package.json +3 -3
- package/src/faq.service.ts +94 -6
package/dist/faq.controller.d.ts
CHANGED
|
@@ -15,9 +15,72 @@ export declare class FAQController {
|
|
|
15
15
|
getFAQStats(): Promise<{
|
|
16
16
|
total: number;
|
|
17
17
|
}>;
|
|
18
|
-
getById(id: number): Promise<
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
getById(id: number): Promise<{
|
|
19
|
+
locale: Record<string, {
|
|
20
|
+
question: string;
|
|
21
|
+
answer: string;
|
|
22
|
+
}>;
|
|
23
|
+
faq_locale: ({
|
|
24
|
+
locale: {
|
|
25
|
+
code: string;
|
|
26
|
+
};
|
|
27
|
+
} & {
|
|
28
|
+
id: number;
|
|
29
|
+
created_at: Date;
|
|
30
|
+
locale_id: number;
|
|
31
|
+
updated_at: Date;
|
|
32
|
+
faq_id: number;
|
|
33
|
+
question: string;
|
|
34
|
+
answer: string;
|
|
35
|
+
})[];
|
|
36
|
+
id: number;
|
|
37
|
+
created_at: Date;
|
|
38
|
+
updated_at: Date;
|
|
39
|
+
}>;
|
|
40
|
+
create(body: FAQDTO): Promise<{
|
|
41
|
+
locale: Record<string, {
|
|
42
|
+
question: string;
|
|
43
|
+
answer: string;
|
|
44
|
+
}>;
|
|
45
|
+
faq_locale: ({
|
|
46
|
+
locale: {
|
|
47
|
+
code: string;
|
|
48
|
+
};
|
|
49
|
+
} & {
|
|
50
|
+
id: number;
|
|
51
|
+
created_at: Date;
|
|
52
|
+
locale_id: number;
|
|
53
|
+
updated_at: Date;
|
|
54
|
+
faq_id: number;
|
|
55
|
+
question: string;
|
|
56
|
+
answer: string;
|
|
57
|
+
})[];
|
|
58
|
+
id: number;
|
|
59
|
+
created_at: Date;
|
|
60
|
+
updated_at: Date;
|
|
61
|
+
}>;
|
|
62
|
+
update(id: number, body: Partial<FAQDTO>): Promise<{
|
|
63
|
+
locale: Record<string, {
|
|
64
|
+
question: string;
|
|
65
|
+
answer: string;
|
|
66
|
+
}>;
|
|
67
|
+
faq_locale: ({
|
|
68
|
+
locale: {
|
|
69
|
+
code: string;
|
|
70
|
+
};
|
|
71
|
+
} & {
|
|
72
|
+
id: number;
|
|
73
|
+
created_at: Date;
|
|
74
|
+
locale_id: number;
|
|
75
|
+
updated_at: Date;
|
|
76
|
+
faq_id: number;
|
|
77
|
+
question: string;
|
|
78
|
+
answer: string;
|
|
79
|
+
})[];
|
|
80
|
+
id: number;
|
|
81
|
+
created_at: Date;
|
|
82
|
+
updated_at: Date;
|
|
83
|
+
}>;
|
|
21
84
|
delete(id: number): Promise<{
|
|
22
85
|
deleted: boolean;
|
|
23
86
|
message: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"faq.controller.d.ts","sourceRoot":"","sources":["../src/faq.controller.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,qBACa,aAAa;IACZ,OAAO,CAAC,QAAQ,CAAC,UAAU;gBAAV,UAAU,EAAE,UAAU;IAG7C,IAAI,CACM,gBAAgB,KAAA,EACpB,MAAM,EAAE,MAAM;;;;;;;;;IAMpB,WAAW;;;IAKX,OAAO,CACgB,EAAE,EAAE,MAAM
|
|
1
|
+
{"version":3,"file":"faq.controller.d.ts","sourceRoot":"","sources":["../src/faq.controller.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,qBACa,aAAa;IACZ,OAAO,CAAC,QAAQ,CAAC,UAAU;gBAAV,UAAU,EAAE,UAAU;IAG7C,IAAI,CACM,gBAAgB,KAAA,EACpB,MAAM,EAAE,MAAM;;;;;;;;;IAMpB,WAAW;;;IAKX,OAAO,CACgB,EAAE,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;IAYjC,MAAM,CACF,IAAI,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;IAMhB,MAAM,CACiB,EAAE,EAAE,MAAM,EAC7B,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC;;;;;;;;;;;;;;;;;;;;;;IAMzB,MAAM,CAA4B,EAAE,EAAE,MAAM;;;;CAGnD"}
|
package/dist/faq.service.d.ts
CHANGED
|
@@ -17,9 +17,72 @@ export declare class FAQService {
|
|
|
17
17
|
getStats(): Promise<{
|
|
18
18
|
total: number;
|
|
19
19
|
}>;
|
|
20
|
-
create(body: FAQDTO): Promise<
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
create(body: FAQDTO): Promise<{
|
|
21
|
+
locale: Record<string, {
|
|
22
|
+
question: string;
|
|
23
|
+
answer: string;
|
|
24
|
+
}>;
|
|
25
|
+
faq_locale: ({
|
|
26
|
+
locale: {
|
|
27
|
+
code: string;
|
|
28
|
+
};
|
|
29
|
+
} & {
|
|
30
|
+
id: number;
|
|
31
|
+
created_at: Date;
|
|
32
|
+
locale_id: number;
|
|
33
|
+
updated_at: Date;
|
|
34
|
+
faq_id: number;
|
|
35
|
+
question: string;
|
|
36
|
+
answer: string;
|
|
37
|
+
})[];
|
|
38
|
+
id: number;
|
|
39
|
+
created_at: Date;
|
|
40
|
+
updated_at: Date;
|
|
41
|
+
}>;
|
|
42
|
+
getById(id: number): Promise<{
|
|
43
|
+
locale: Record<string, {
|
|
44
|
+
question: string;
|
|
45
|
+
answer: string;
|
|
46
|
+
}>;
|
|
47
|
+
faq_locale: ({
|
|
48
|
+
locale: {
|
|
49
|
+
code: string;
|
|
50
|
+
};
|
|
51
|
+
} & {
|
|
52
|
+
id: number;
|
|
53
|
+
created_at: Date;
|
|
54
|
+
locale_id: number;
|
|
55
|
+
updated_at: Date;
|
|
56
|
+
faq_id: number;
|
|
57
|
+
question: string;
|
|
58
|
+
answer: string;
|
|
59
|
+
})[];
|
|
60
|
+
id: number;
|
|
61
|
+
created_at: Date;
|
|
62
|
+
updated_at: Date;
|
|
63
|
+
}>;
|
|
64
|
+
update(id: number, body: Partial<FAQDTO>): Promise<{
|
|
65
|
+
locale: Record<string, {
|
|
66
|
+
question: string;
|
|
67
|
+
answer: string;
|
|
68
|
+
}>;
|
|
69
|
+
faq_locale: ({
|
|
70
|
+
locale: {
|
|
71
|
+
code: string;
|
|
72
|
+
};
|
|
73
|
+
} & {
|
|
74
|
+
id: number;
|
|
75
|
+
created_at: Date;
|
|
76
|
+
locale_id: number;
|
|
77
|
+
updated_at: Date;
|
|
78
|
+
faq_id: number;
|
|
79
|
+
question: string;
|
|
80
|
+
answer: string;
|
|
81
|
+
})[];
|
|
82
|
+
id: number;
|
|
83
|
+
created_at: Date;
|
|
84
|
+
updated_at: Date;
|
|
85
|
+
}>;
|
|
23
86
|
delete(id: number): Promise<{
|
|
24
87
|
deleted: boolean;
|
|
25
88
|
message: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"faq.service.d.ts","sourceRoot":"","sources":["../src/faq.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC,qBACa,UAAU;IAEnB,OAAO,CAAC,QAAQ,CAAC,MAAM;IAEvB,OAAO,CAAC,QAAQ,CAAC,aAAa;gBAFb,MAAM,EAAE,aAAa,EAErB,aAAa,EAAE,aAAa;IAGzC,IAAI,CAAC,gBAAgB,KAAA,EAAE,MAAM,EAAE,MAAM;cAkEzB,GAAG,EAAE;;;;;;;;IAUjB,QAAQ;;;IAOR,MAAM,CAAC,IAAI,EAAE,MAAM;
|
|
1
|
+
{"version":3,"file":"faq.service.d.ts","sourceRoot":"","sources":["../src/faq.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC,qBACa,UAAU;IAEnB,OAAO,CAAC,QAAQ,CAAC,MAAM;IAEvB,OAAO,CAAC,QAAQ,CAAC,aAAa;gBAFb,MAAM,EAAE,aAAa,EAErB,aAAa,EAAE,aAAa;IAGzC,IAAI,CAAC,gBAAgB,KAAA,EAAE,MAAM,EAAE,MAAM;cAkEzB,GAAG,EAAE;;;;;;;;IAUjB,QAAQ;;;IAOR,MAAM,CAAC,IAAI,EAAE,MAAM;;sBAoDa,MAAM;oBAAU,MAAM;;;;;;;;;;;;;;;;;;;IAzBtD,OAAO,CAAC,EAAE,EAAE,MAAM;;sBAyBc,MAAM;oBAAU,MAAM;;;;;;;;;;;;;;;;;;;IAQtD,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC;;sBARR,MAAM;oBAAU,MAAM;;;;;;;;;;;;;;;;;;;IAgDtD,MAAM,CAAC,EAAE,EAAE,MAAM;;;;CAqBxB"}
|
package/dist/faq.service.js
CHANGED
|
@@ -95,13 +95,84 @@ let FAQService = class FAQService {
|
|
|
95
95
|
};
|
|
96
96
|
}
|
|
97
97
|
async create(body) {
|
|
98
|
-
|
|
98
|
+
const { locale } = body;
|
|
99
|
+
const faq = await this.prisma.faq.create({
|
|
100
|
+
data: {},
|
|
101
|
+
});
|
|
102
|
+
if (locale) {
|
|
103
|
+
await Promise.all(Object.entries(locale).map(async ([localeCode, localeData]) => {
|
|
104
|
+
const localeRecord = await this.localeService.getByCode(localeCode);
|
|
105
|
+
await this.prisma.faq_locale.create({
|
|
106
|
+
data: {
|
|
107
|
+
faq_id: faq.id,
|
|
108
|
+
locale_id: localeRecord.id,
|
|
109
|
+
question: localeData.question,
|
|
110
|
+
answer: localeData.answer,
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
}));
|
|
114
|
+
}
|
|
115
|
+
return this.getById(faq.id);
|
|
99
116
|
}
|
|
100
117
|
async getById(id) {
|
|
101
|
-
|
|
118
|
+
const faq = await this.prisma.faq.findUnique({
|
|
119
|
+
where: { id },
|
|
120
|
+
include: {
|
|
121
|
+
faq_locale: {
|
|
122
|
+
include: {
|
|
123
|
+
locale: {
|
|
124
|
+
select: { code: true },
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
if (!faq) {
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
const localeData = faq.faq_locale.reduce((acc, item) => {
|
|
134
|
+
const localeCode = item.locale.code;
|
|
135
|
+
acc[localeCode] = {
|
|
136
|
+
question: item.question,
|
|
137
|
+
answer: item.answer,
|
|
138
|
+
};
|
|
139
|
+
return acc;
|
|
140
|
+
}, {});
|
|
141
|
+
return Object.assign(Object.assign({}, faq), { locale: localeData });
|
|
102
142
|
}
|
|
103
143
|
async update(id, body) {
|
|
104
|
-
|
|
144
|
+
const { locale } = body;
|
|
145
|
+
if (locale) {
|
|
146
|
+
await Promise.all(Object.entries(locale).map(async ([localeCode, localeData]) => {
|
|
147
|
+
const localeRecord = await this.localeService.getByCode(localeCode);
|
|
148
|
+
const existing = await this.prisma.faq_locale.findFirst({
|
|
149
|
+
where: {
|
|
150
|
+
faq_id: id,
|
|
151
|
+
locale_id: localeRecord.id,
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
if (existing) {
|
|
155
|
+
await this.prisma.faq_locale.update({
|
|
156
|
+
where: { id: existing.id },
|
|
157
|
+
data: {
|
|
158
|
+
question: localeData.question,
|
|
159
|
+
answer: localeData.answer,
|
|
160
|
+
},
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
await this.prisma.faq_locale.create({
|
|
165
|
+
data: {
|
|
166
|
+
faq_id: id,
|
|
167
|
+
locale_id: localeRecord.id,
|
|
168
|
+
question: localeData.question,
|
|
169
|
+
answer: localeData.answer,
|
|
170
|
+
},
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
}));
|
|
174
|
+
}
|
|
175
|
+
return this.getById(id);
|
|
105
176
|
}
|
|
106
177
|
async delete(id) {
|
|
107
178
|
const faq = await this.prisma.faq.findUnique({
|
package/dist/faq.service.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"faq.service.js","sourceRoot":"","sources":["../src/faq.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,oDAAoD;AACpD,oDAAoD;AACpD,2CAAgE;AAIzD,IAAM,UAAU,GAAhB,MAAM,UAAU;IACrB,YACmB,MAAqB,EAErB,aAA4B;QAF5B,WAAM,GAAN,MAAM,CAAe;QAErB,kBAAa,GAAb,aAAa,CAAe;IAC5C,CAAC;IAEJ,KAAK,CAAC,IAAI,CAAC,gBAAgB,EAAE,MAAc;;QACzC,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAChE,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,MAAM,IAAI,KAAK,CAAC,UAAU,MAAM,YAAY,CAAC,CAAC;QAChD,CAAC;QACD,MAAM,QAAQ,GAAG,YAAY,CAAC,EAAE,CAAC;QAEjC,MAAM,SAAS,GAAG,CAAC,MAAA,gBAAgB,CAAC,MAAM,mCAAI,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC;QACpE,MAAM,SAAS,GAAG,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC;QACvC,MAAM,IA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AAC;gBACL,CAAC;YACH,CAAC,CAAC,CACH,CAAC;QACJ,CAAC;QAED,OAAO,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,EAAU;QACrB,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC;YAC3C,KAAK,EAAE,EAAE,EAAE,EAAE;SACd,CAAC,CAAC;QAEH,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,OAAO,EAAE,eAAe;aACzB,CAAC;QACJ,CAAC;QAED,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC;YAC3B,KAAK,EAAE,EAAE,EAAE,EAAE;SACd,CAAC,CAAC;QAEH,OAAO;YACL,OAAO,EAAE,IAAI;YACb,OAAO,EAAE,0BAA0B;SACpC,CAAC;IACJ,CAAC;CACF,CAAA;AAnNY,gCAAU;qBAAV,UAAU;IADtB,IAAA,mBAAU,GAAE;IAIR,WAAA,IAAA,eAAM,EAAC,IAAA,mBAAU,EAAC,GAAG,EAAE,CAAC,0BAAa,CAAC,CAAC,CAAA;qCADf,0BAAa;QAEN,0BAAa;GAJpC,UAAU,CAmNtB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hed-hog/faq",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"dependencies": {
|
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
"@nestjs/core": "^11",
|
|
10
10
|
"@nestjs/jwt": "^11",
|
|
11
11
|
"@nestjs/mapped-types": "*",
|
|
12
|
-
"@hed-hog/admin": "0.0.129",
|
|
13
|
-
"@hed-hog/api": "0.0.3",
|
|
14
12
|
"@hed-hog/api-locale": "0.0.10",
|
|
13
|
+
"@hed-hog/admin": "0.0.130",
|
|
14
|
+
"@hed-hog/api": "0.0.3",
|
|
15
15
|
"@hed-hog/api-pagination": "0.0.3",
|
|
16
16
|
"@hed-hog/api-prisma": "0.0.4"
|
|
17
17
|
},
|
package/src/faq.service.ts
CHANGED
|
@@ -94,16 +94,104 @@ export class FAQService {
|
|
|
94
94
|
};
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
async create(body: FAQDTO){
|
|
98
|
-
|
|
97
|
+
async create(body: FAQDTO) {
|
|
98
|
+
const { locale } = body;
|
|
99
|
+
|
|
100
|
+
const faq = await this.prisma.faq.create({
|
|
101
|
+
data: {},
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
if (locale) {
|
|
105
|
+
await Promise.all(
|
|
106
|
+
Object.entries(locale).map(async ([localeCode, localeData]) => {
|
|
107
|
+
const localeRecord = await this.localeService.getByCode(localeCode);
|
|
108
|
+
|
|
109
|
+
await this.prisma.faq_locale.create({
|
|
110
|
+
data: {
|
|
111
|
+
faq_id: faq.id,
|
|
112
|
+
locale_id: localeRecord.id,
|
|
113
|
+
question: localeData.question,
|
|
114
|
+
answer: localeData.answer,
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
})
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return this.getById(faq.id);
|
|
99
122
|
}
|
|
100
123
|
|
|
101
|
-
async getById(id: number){
|
|
102
|
-
|
|
124
|
+
async getById(id: number) {
|
|
125
|
+
const faq = await this.prisma.faq.findUnique({
|
|
126
|
+
where: { id },
|
|
127
|
+
include: {
|
|
128
|
+
faq_locale: {
|
|
129
|
+
include: {
|
|
130
|
+
locale: {
|
|
131
|
+
select: { code: true },
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
if (!faq) {
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const localeData = faq.faq_locale.reduce((acc, item) => {
|
|
143
|
+
const localeCode = item.locale.code;
|
|
144
|
+
acc[localeCode] = {
|
|
145
|
+
question: item.question,
|
|
146
|
+
answer: item.answer,
|
|
147
|
+
};
|
|
148
|
+
return acc;
|
|
149
|
+
}, {} as Record<string, { question: string; answer: string }>);
|
|
150
|
+
|
|
151
|
+
return {
|
|
152
|
+
...faq,
|
|
153
|
+
locale: localeData,
|
|
154
|
+
};
|
|
103
155
|
}
|
|
104
156
|
|
|
105
|
-
async update(id: number, body: Partial<FAQDTO>){
|
|
106
|
-
|
|
157
|
+
async update(id: number, body: Partial<FAQDTO>) {
|
|
158
|
+
const { locale } = body;
|
|
159
|
+
|
|
160
|
+
if (locale) {
|
|
161
|
+
await Promise.all(
|
|
162
|
+
Object.entries(locale).map(async ([localeCode, localeData]) => {
|
|
163
|
+
const localeRecord = await this.localeService.getByCode(localeCode);
|
|
164
|
+
|
|
165
|
+
const existing = await this.prisma.faq_locale.findFirst({
|
|
166
|
+
where: {
|
|
167
|
+
faq_id: id,
|
|
168
|
+
locale_id: localeRecord.id,
|
|
169
|
+
},
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
if (existing) {
|
|
173
|
+
await this.prisma.faq_locale.update({
|
|
174
|
+
where: { id: existing.id },
|
|
175
|
+
data: {
|
|
176
|
+
question: localeData.question,
|
|
177
|
+
answer: localeData.answer,
|
|
178
|
+
},
|
|
179
|
+
});
|
|
180
|
+
} else {
|
|
181
|
+
await this.prisma.faq_locale.create({
|
|
182
|
+
data: {
|
|
183
|
+
faq_id: id,
|
|
184
|
+
locale_id: localeRecord.id,
|
|
185
|
+
question: localeData.question,
|
|
186
|
+
answer: localeData.answer,
|
|
187
|
+
},
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
})
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return this.getById(id);
|
|
107
195
|
}
|
|
108
196
|
|
|
109
197
|
async delete(id: number){
|