@hed-hog/content 0.0.1 → 0.0.3
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/content.controller.d.ts +35 -7
- package/dist/content.controller.d.ts.map +1 -1
- package/dist/content.service.d.ts +35 -7
- package/dist/content.service.d.ts.map +1 -1
- package/dist/content.service.js +59 -6
- package/dist/content.service.js.map +1 -1
- package/package.json +4 -4
- package/src/content.service.ts +78 -12
|
@@ -6,12 +6,22 @@ export declare class ContentController {
|
|
|
6
6
|
private readonly contentService;
|
|
7
7
|
constructor(contentService: ContentService);
|
|
8
8
|
getContentStats(): Promise<{
|
|
9
|
-
total:
|
|
10
|
-
totalPublished:
|
|
11
|
-
totalDraft:
|
|
9
|
+
total: number;
|
|
10
|
+
totalPublished: number;
|
|
11
|
+
totalDraft: number;
|
|
12
12
|
totalEnabledLanguages: number;
|
|
13
13
|
}>;
|
|
14
|
-
getContent(id: number): Promise<
|
|
14
|
+
getContent(id: number): Promise<{
|
|
15
|
+
id: number;
|
|
16
|
+
slug: string;
|
|
17
|
+
status: import("@prisma/client").$Enums.content_status_enum;
|
|
18
|
+
created_at: Date;
|
|
19
|
+
updated_at: Date;
|
|
20
|
+
locales: Record<string, {
|
|
21
|
+
title: string;
|
|
22
|
+
body: string;
|
|
23
|
+
}>;
|
|
24
|
+
}>;
|
|
15
25
|
getContents(locale: string, paginationParams: PaginationDTO, query: any): Promise<{
|
|
16
26
|
total: any;
|
|
17
27
|
lastPage: number;
|
|
@@ -21,8 +31,26 @@ export declare class ContentController {
|
|
|
21
31
|
next: number;
|
|
22
32
|
data: any;
|
|
23
33
|
}>;
|
|
24
|
-
deleteContent(locale: string, id: number): Promise<
|
|
25
|
-
|
|
26
|
-
|
|
34
|
+
deleteContent(locale: string, id: number): Promise<{
|
|
35
|
+
id: number;
|
|
36
|
+
created_at: Date;
|
|
37
|
+
updated_at: Date;
|
|
38
|
+
slug: string;
|
|
39
|
+
status: import("@prisma/client").$Enums.content_status_enum;
|
|
40
|
+
}>;
|
|
41
|
+
createContent(localeStr: string, { slug, status, locale }: ContentCreateDTO): Promise<{
|
|
42
|
+
id: number;
|
|
43
|
+
created_at: Date;
|
|
44
|
+
updated_at: Date;
|
|
45
|
+
slug: string;
|
|
46
|
+
status: import("@prisma/client").$Enums.content_status_enum;
|
|
47
|
+
}>;
|
|
48
|
+
updateContent(localeStr: string, id: number, { locale, slug, status }: ContentUpdateDTO): Promise<{
|
|
49
|
+
id: number;
|
|
50
|
+
created_at: Date;
|
|
51
|
+
updated_at: Date;
|
|
52
|
+
slug: string;
|
|
53
|
+
status: import("@prisma/client").$Enums.content_status_enum;
|
|
54
|
+
}>;
|
|
27
55
|
}
|
|
28
56
|
//# sourceMappingURL=content.controller.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content.controller.d.ts","sourceRoot":"","sources":["../src/content.controller.ts"],"names":[],"mappings":"AACA,OAAO,EAAc,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAYpE,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAE5D,qBACa,iBAAiB;IAE1B,OAAO,CAAC,QAAQ,CAAC,cAAc;gBAAd,cAAc,EAAE,cAAc;IAI3C,eAAe;;;;;;IAKf,UAAU,CAA4B,EAAE,EAAE,MAAM
|
|
1
|
+
{"version":3,"file":"content.controller.d.ts","sourceRoot":"","sources":["../src/content.controller.ts"],"names":[],"mappings":"AACA,OAAO,EAAc,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAYpE,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAE5D,qBACa,iBAAiB;IAE1B,OAAO,CAAC,QAAQ,CAAC,cAAc;gBAAd,cAAc,EAAE,cAAc;IAI3C,eAAe;;;;;;IAKf,UAAU,CAA4B,EAAE,EAAE,MAAM;;;;;;;;;;;IAKhD,WAAW,CAAW,MAAM,EAAE,MAAM,EAAgB,gBAAgB,EAAE,aAAa,EAAW,KAAK,EAAE,GAAG;;;;;;;;;IAKxG,aAAa,CAAW,MAAM,EAAE,MAAM,EAA6B,EAAE,EAAE,MAAM;;;;;;;IAK7E,aAAa,CAAW,SAAS,EAAE,MAAM,EAAU,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,gBAAgB;;;;;;;IAS7F,aAAa,CACP,SAAS,EAAE,MAAM,EACA,EAAE,EAAE,MAAM,EAC7B,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,gBAAgB;;;;;;;CAQrD"}
|
|
@@ -9,12 +9,22 @@ export declare class ContentService {
|
|
|
9
9
|
private readonly locale;
|
|
10
10
|
constructor(prisma: PrismaService, pagination: PaginationService, locale: LocaleService);
|
|
11
11
|
getContentStats(): Promise<{
|
|
12
|
-
total:
|
|
13
|
-
totalPublished:
|
|
14
|
-
totalDraft:
|
|
12
|
+
total: number;
|
|
13
|
+
totalPublished: number;
|
|
14
|
+
totalDraft: number;
|
|
15
15
|
totalEnabledLanguages: number;
|
|
16
16
|
}>;
|
|
17
|
-
getContent(id: number): Promise<
|
|
17
|
+
getContent(id: number): Promise<{
|
|
18
|
+
id: number;
|
|
19
|
+
slug: string;
|
|
20
|
+
status: import("@prisma/client").$Enums.content_status_enum;
|
|
21
|
+
created_at: Date;
|
|
22
|
+
updated_at: Date;
|
|
23
|
+
locales: Record<string, {
|
|
24
|
+
title: string;
|
|
25
|
+
body: string;
|
|
26
|
+
}>;
|
|
27
|
+
}>;
|
|
18
28
|
getContents(locale: string, paginationParams: PaginationDTO, query: any): Promise<{
|
|
19
29
|
total: any;
|
|
20
30
|
lastPage: number;
|
|
@@ -24,8 +34,26 @@ export declare class ContentService {
|
|
|
24
34
|
next: number;
|
|
25
35
|
data: any;
|
|
26
36
|
}>;
|
|
27
|
-
deleteContent(locale: string, id: number): Promise<
|
|
28
|
-
|
|
29
|
-
|
|
37
|
+
deleteContent(locale: string, id: number): Promise<{
|
|
38
|
+
id: number;
|
|
39
|
+
created_at: Date;
|
|
40
|
+
updated_at: Date;
|
|
41
|
+
slug: string;
|
|
42
|
+
status: import("@prisma/client").$Enums.content_status_enum;
|
|
43
|
+
}>;
|
|
44
|
+
createContent(localeStr: string, { locale, slug, status }: ContentCreateDTO): Promise<{
|
|
45
|
+
id: number;
|
|
46
|
+
created_at: Date;
|
|
47
|
+
updated_at: Date;
|
|
48
|
+
slug: string;
|
|
49
|
+
status: import("@prisma/client").$Enums.content_status_enum;
|
|
50
|
+
}>;
|
|
51
|
+
updateContent(localeStr: string, id: number, { locale, slug, status }: ContentUpdateDTO): Promise<{
|
|
52
|
+
id: number;
|
|
53
|
+
created_at: Date;
|
|
54
|
+
updated_at: Date;
|
|
55
|
+
slug: string;
|
|
56
|
+
status: import("@prisma/client").$Enums.content_status_enum;
|
|
57
|
+
}>;
|
|
30
58
|
}
|
|
31
59
|
//# sourceMappingURL=content.service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content.service.d.ts","sourceRoot":"","sources":["../src/content.service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"content.service.d.ts","sourceRoot":"","sources":["../src/content.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAE5D,qBACa,cAAc;IAEvB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAFN,MAAM,EAAE,aAAa,EACrB,UAAU,EAAE,iBAAiB,EAC7B,MAAM,EAAE,aAAa;IAGlC,eAAe;;;;;;IAyBf,UAAU,CAAC,EAAE,EAAE,MAAM;;;;;;;mBAekB,MAAM;kBAAQ,MAAM;;;IAsB3D,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,aAAa,EAAE,KAAK,EAAE,GAAG;;;;;;;;;IA4EvE,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM;;;;;;;IAcxC,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,gBAAgB;;;;;;;IAuC3E,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,gBAAgB;;;;;;;CAmD9F"}
|
package/dist/content.service.js
CHANGED
|
@@ -10,7 +10,6 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.ContentService = void 0;
|
|
13
|
-
const api_1 = require("@hed-hog/api");
|
|
14
13
|
const api_locale_1 = require("@hed-hog/api-locale");
|
|
15
14
|
const api_pagination_1 = require("@hed-hog/api-pagination");
|
|
16
15
|
const api_prisma_1 = require("@hed-hog/api-prisma");
|
|
@@ -40,9 +39,38 @@ let ContentService = class ContentService {
|
|
|
40
39
|
};
|
|
41
40
|
}
|
|
42
41
|
async getContent(id) {
|
|
43
|
-
|
|
44
|
-
id: Number(id),
|
|
45
|
-
|
|
42
|
+
const content = await this.prisma.content.findUnique({
|
|
43
|
+
where: { id: Number(id) },
|
|
44
|
+
include: {
|
|
45
|
+
content_locale: {
|
|
46
|
+
where: { locale: { enabled: true } },
|
|
47
|
+
include: { locale: { select: { code: true } } },
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
if (!content) {
|
|
52
|
+
throw new common_1.NotFoundException((0, api_locale_1.getLocaleText)('contentNotFound', 'en', 'Content not found'));
|
|
53
|
+
}
|
|
54
|
+
const localesData = {};
|
|
55
|
+
if (content.content_locale && Array.isArray(content.content_locale)) {
|
|
56
|
+
content.content_locale.forEach((cl) => {
|
|
57
|
+
var _a;
|
|
58
|
+
if ((_a = cl.locale) === null || _a === void 0 ? void 0 : _a.code) {
|
|
59
|
+
localesData[cl.locale.code] = {
|
|
60
|
+
title: cl.title || '',
|
|
61
|
+
body: cl.body || '',
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
id: content.id,
|
|
68
|
+
slug: content.slug,
|
|
69
|
+
status: content.status,
|
|
70
|
+
created_at: content.created_at,
|
|
71
|
+
updated_at: content.updated_at,
|
|
72
|
+
locales: localesData,
|
|
73
|
+
};
|
|
46
74
|
}
|
|
47
75
|
async getContents(locale, paginationParams, query) {
|
|
48
76
|
const localeRecord = await this.locale.getByCode(locale);
|
|
@@ -65,12 +93,37 @@ let ContentService = class ContentService {
|
|
|
65
93
|
include: {
|
|
66
94
|
content_locale: {
|
|
67
95
|
where: {
|
|
68
|
-
|
|
96
|
+
locale: {
|
|
97
|
+
enabled: true,
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
include: {
|
|
101
|
+
locale: {
|
|
102
|
+
select: {
|
|
103
|
+
id: true,
|
|
104
|
+
code: true,
|
|
105
|
+
name: true,
|
|
106
|
+
},
|
|
107
|
+
},
|
|
69
108
|
},
|
|
70
109
|
},
|
|
71
110
|
},
|
|
72
111
|
}, locale);
|
|
73
|
-
result.data = result.data.map((content) =>
|
|
112
|
+
result.data = result.data.map((content) => {
|
|
113
|
+
var _a, _b;
|
|
114
|
+
const currentLocaleData = (_a = content.content_locale) === null || _a === void 0 ? void 0 : _a.find((cl) => cl.locale_id === localeRecord.id);
|
|
115
|
+
const translatedContent = Object.assign(Object.assign({}, content), { title: (currentLocaleData === null || currentLocaleData === void 0 ? void 0 : currentLocaleData.title) || '', body: (currentLocaleData === null || currentLocaleData === void 0 ? void 0 : currentLocaleData.body) || '' });
|
|
116
|
+
delete translatedContent.content_locale;
|
|
117
|
+
const availableLocales = Array.from(new Map(((_b = content.content_locale) === null || _b === void 0 ? void 0 : _b.map((cl) => [
|
|
118
|
+
cl.locale.id,
|
|
119
|
+
{
|
|
120
|
+
id: cl.locale.id,
|
|
121
|
+
code: cl.locale.code,
|
|
122
|
+
name: cl.locale.name,
|
|
123
|
+
}
|
|
124
|
+
])) || []).values());
|
|
125
|
+
return Object.assign(Object.assign({}, translatedContent), { available_locales: availableLocales });
|
|
126
|
+
});
|
|
74
127
|
return result;
|
|
75
128
|
}
|
|
76
129
|
async deleteContent(locale, id) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content.service.js","sourceRoot":"","sources":["../src/content.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"content.service.js","sourceRoot":"","sources":["../src/content.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAAmE;AACnE,4DAA2E;AAC3E,oDAAoD;AACpD,2CAAoF;AAK7E,IAAM,cAAc,GAApB,MAAM,cAAc;IACzB,YACmB,MAAqB,EACrB,UAA6B,EAC7B,MAAqB;QAFrB,WAAM,GAAN,MAAM,CAAe;QACrB,eAAU,GAAV,UAAU,CAAmB;QAC7B,WAAM,GAAN,MAAM,CAAe;IACrC,CAAC;IAEJ,KAAK,CAAC,eAAe;QACnB,MAAM,QAAQ,GAAG,CAAC,WAAW,EAAE,OAAO,CAAU,CAAC;QAEjD,MAAM,CAA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AAE,EAAE;wBAChC,IAAI,EAAE,EAAE,KAAK,EAAE,UAAU,CAAC,KAAK,EAAE,IAAI,EAAE,UAAU,CAAC,IAAI,EAAE;qBACzD,CAAC,CAAC;gBACL,CAAC;qBAAM,CAAC;oBACN,MAAM,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC;wBACtC,IAAI,EAAE;4BACJ,UAAU,EAAE,MAAM,CAAC,EAAE,CAAC;4BACtB,SAAS,EAAE,YAAY,CAAC,EAAE;4BAC1B,KAAK,EAAE,UAAU,CAAC,KAAK;4BACvB,IAAI,EAAE,UAAU,CAAC,IAAI;yBACtB;qBACF,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,cAAc,CAAA;IACvB,CAAC;CACF,CAAA;AAzPY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,mBAAU,GAAE;qCAGgB,0BAAa;QACT,kCAAiB;QACrB,0BAAa;GAJ7B,cAAc,CAyP1B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hed-hog/content",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"dependencies": {
|
|
@@ -9,11 +9,11 @@
|
|
|
9
9
|
"@nestjs/core": "^11",
|
|
10
10
|
"@nestjs/jwt": "^11",
|
|
11
11
|
"@nestjs/mapped-types": "*",
|
|
12
|
-
"@hed-hog/core": "0.0.13",
|
|
13
12
|
"@hed-hog/api-locale": "0.0.10",
|
|
13
|
+
"@hed-hog/core": "0.0.20",
|
|
14
14
|
"@hed-hog/api-prisma": "0.0.4",
|
|
15
|
-
"@hed-hog/api
|
|
16
|
-
"@hed-hog/api": "0.0.3"
|
|
15
|
+
"@hed-hog/api": "0.0.3",
|
|
16
|
+
"@hed-hog/api-pagination": "0.0.3"
|
|
17
17
|
},
|
|
18
18
|
"exports": {
|
|
19
19
|
".": {
|
package/src/content.service.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { itemTranslations } from '@hed-hog/api';
|
|
2
1
|
import { getLocaleText, LocaleService } from '@hed-hog/api-locale';
|
|
3
2
|
import { PaginationDTO, PaginationService } from '@hed-hog/api-pagination';
|
|
4
3
|
import { PrismaService } from '@hed-hog/api-prisma';
|
|
@@ -40,13 +39,41 @@ export class ContentService {
|
|
|
40
39
|
}
|
|
41
40
|
|
|
42
41
|
async getContent(id: number) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
42
|
+
const content = await this.prisma.content.findUnique({
|
|
43
|
+
where: { id: Number(id) },
|
|
44
|
+
include: {
|
|
45
|
+
content_locale: {
|
|
46
|
+
where: { locale: { enabled: true } },
|
|
47
|
+
include: { locale: { select: { code: true } } },
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
if (!content) {
|
|
53
|
+
throw new NotFoundException(getLocaleText('contentNotFound', 'en', 'Content not found'));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const localesData: Record<string, { title: string; body: string }> = {};
|
|
57
|
+
if (content.content_locale && Array.isArray(content.content_locale)) {
|
|
58
|
+
content.content_locale.forEach((cl: any) => {
|
|
59
|
+
if (cl.locale?.code) {
|
|
60
|
+
localesData[cl.locale.code] = {
|
|
61
|
+
title: cl.title || '',
|
|
62
|
+
body: cl.body || '',
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
id: content.id,
|
|
70
|
+
slug: content.slug,
|
|
71
|
+
status: content.status,
|
|
72
|
+
created_at: content.created_at,
|
|
73
|
+
updated_at: content.updated_at,
|
|
74
|
+
locales: localesData,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
50
77
|
|
|
51
78
|
async getContents(locale: string, paginationParams: PaginationDTO, query: any) {
|
|
52
79
|
const localeRecord = await this.locale.getByCode(locale);
|
|
@@ -72,15 +99,54 @@ export class ContentService {
|
|
|
72
99
|
include: {
|
|
73
100
|
content_locale: {
|
|
74
101
|
where: {
|
|
75
|
-
|
|
102
|
+
locale: {
|
|
103
|
+
enabled: true,
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
include: {
|
|
107
|
+
locale: {
|
|
108
|
+
select: {
|
|
109
|
+
id: true,
|
|
110
|
+
code: true,
|
|
111
|
+
name: true,
|
|
112
|
+
},
|
|
113
|
+
},
|
|
76
114
|
},
|
|
77
115
|
},
|
|
78
116
|
},
|
|
79
117
|
}, locale);
|
|
80
118
|
|
|
81
|
-
result.data = result.data.map((content) =>
|
|
82
|
-
|
|
83
|
-
|
|
119
|
+
result.data = result.data.map((content: any) => {
|
|
120
|
+
const currentLocaleData = content.content_locale?.find(
|
|
121
|
+
(cl: any) => cl.locale_id === localeRecord.id
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
const translatedContent = {
|
|
125
|
+
...content,
|
|
126
|
+
title: currentLocaleData?.title || '',
|
|
127
|
+
body: currentLocaleData?.body || '',
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
delete translatedContent.content_locale;
|
|
131
|
+
|
|
132
|
+
const availableLocales = Array.from(
|
|
133
|
+
new Map(
|
|
134
|
+
content.content_locale?.map((cl: any) => [
|
|
135
|
+
cl.locale.id,
|
|
136
|
+
{
|
|
137
|
+
id: cl.locale.id,
|
|
138
|
+
code: cl.locale.code,
|
|
139
|
+
name: cl.locale.name,
|
|
140
|
+
}
|
|
141
|
+
]) || []
|
|
142
|
+
).values()
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
return {
|
|
146
|
+
...translatedContent,
|
|
147
|
+
available_locales: availableLocales,
|
|
148
|
+
};
|
|
149
|
+
});
|
|
84
150
|
|
|
85
151
|
return result;
|
|
86
152
|
}
|