@buunguyen3589/collections-module 1.0.0
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/app/index.d.ts +1 -0
- package/dist/app/index.js +17 -0
- package/dist/app/usecases/command/create-collection.usecase.d.ts +16 -0
- package/dist/app/usecases/command/create-collection.usecase.js +66 -0
- package/dist/app/usecases/command/delete-collection.usecase.d.ts +13 -0
- package/dist/app/usecases/command/delete-collection.usecase.js +57 -0
- package/dist/app/usecases/command/index.d.ts +5 -0
- package/dist/app/usecases/command/index.js +21 -0
- package/dist/app/usecases/command/post-collection/index.d.ts +1 -0
- package/dist/app/usecases/command/post-collection/index.js +17 -0
- package/dist/app/usecases/command/post-collection/upsert-post-collection.usecase.d.ts +14 -0
- package/dist/app/usecases/command/post-collection/upsert-post-collection.usecase.js +63 -0
- package/dist/app/usecases/command/product-collection/add-all-products-collection.usecase.d.ts +24 -0
- package/dist/app/usecases/command/product-collection/add-all-products-collection.usecase.js +93 -0
- package/dist/app/usecases/command/product-collection/create-product-collection.usecase.d.ts +24 -0
- package/dist/app/usecases/command/product-collection/create-product-collection.usecase.js +94 -0
- package/dist/app/usecases/command/product-collection/delete-product-collection.usecase.d.ts +14 -0
- package/dist/app/usecases/command/product-collection/delete-product-collection.usecase.js +56 -0
- package/dist/app/usecases/command/product-collection/index.d.ts +3 -0
- package/dist/app/usecases/command/product-collection/index.js +19 -0
- package/dist/app/usecases/command/update-collection.usecase.d.ts +15 -0
- package/dist/app/usecases/command/update-collection.usecase.js +73 -0
- package/dist/app/usecases/index.d.ts +2 -0
- package/dist/app/usecases/index.js +18 -0
- package/dist/app/usecases/query/get-detail-collection.usecase.d.ts +36 -0
- package/dist/app/usecases/query/get-detail-collection.usecase.js +216 -0
- package/dist/app/usecases/query/get-list-collection.usecase.d.ts +23 -0
- package/dist/app/usecases/query/get-list-collection.usecase.js +96 -0
- package/dist/app/usecases/query/get-products-by-collections-internal.usecase.d.ts +19 -0
- package/dist/app/usecases/query/get-products-by-collections-internal.usecase.js +65 -0
- package/dist/app/usecases/query/get-products-by-collections.usecase.d.ts +44 -0
- package/dist/app/usecases/query/get-products-by-collections.usecase.js +130 -0
- package/dist/app/usecases/query/index.d.ts +4 -0
- package/dist/app/usecases/query/index.js +20 -0
- package/dist/collection.module.d.ts +2 -0
- package/dist/collection.module.js +62 -0
- package/dist/domain/aggregates/enums/collection.enum.d.ts +5 -0
- package/dist/domain/aggregates/enums/collection.enum.js +9 -0
- package/dist/domain/aggregates/enums/index.d.ts +1 -0
- package/dist/domain/aggregates/enums/index.js +17 -0
- package/dist/domain/aggregates/index.d.ts +2 -0
- package/dist/domain/aggregates/index.js +18 -0
- package/dist/domain/aggregates/types/collection.type.d.ts +14 -0
- package/dist/domain/aggregates/types/collection.type.js +2 -0
- package/dist/domain/aggregates/types/index.d.ts +3 -0
- package/dist/domain/aggregates/types/index.js +19 -0
- package/dist/domain/aggregates/types/post-collection.type.d.ts +12 -0
- package/dist/domain/aggregates/types/post-collection.type.js +2 -0
- package/dist/domain/aggregates/types/product-collection.type.d.ts +11 -0
- package/dist/domain/aggregates/types/product-collection.type.js +2 -0
- package/dist/domain/builders/collection.builder.d.ts +8 -0
- package/dist/domain/builders/collection.builder.js +38 -0
- package/dist/domain/builders/index.d.ts +3 -0
- package/dist/domain/builders/index.js +19 -0
- package/dist/domain/builders/post-collection.builder.d.ts +8 -0
- package/dist/domain/builders/post-collection.builder.js +38 -0
- package/dist/domain/builders/product-collection.builder.d.ts +8 -0
- package/dist/domain/builders/product-collection.builder.js +38 -0
- package/dist/domain/consts/event-collection.name.const.d.ts +5 -0
- package/dist/domain/consts/event-collection.name.const.js +8 -0
- package/dist/domain/consts/event-post-collection.name.const.d.ts +6 -0
- package/dist/domain/consts/event-post-collection.name.const.js +9 -0
- package/dist/domain/consts/event-product-collection.name.const.d.ts +5 -0
- package/dist/domain/consts/event-product-collection.name.const.js +8 -0
- package/dist/domain/consts/index.d.ts +3 -0
- package/dist/domain/consts/index.js +19 -0
- package/dist/domain/dtos/collection.dto.d.ts +4 -0
- package/dist/domain/dtos/collection.dto.js +2 -0
- package/dist/domain/dtos/index.d.ts +3 -0
- package/dist/domain/dtos/index.js +19 -0
- package/dist/domain/dtos/post-collection.dto.d.ts +4 -0
- package/dist/domain/dtos/post-collection.dto.js +2 -0
- package/dist/domain/dtos/product-collection.dto.d.ts +4 -0
- package/dist/domain/dtos/product-collection.dto.js +2 -0
- package/dist/domain/entities/collection.entity.d.ts +40 -0
- package/dist/domain/entities/collection.entity.js +87 -0
- package/dist/domain/entities/index.d.ts +3 -0
- package/dist/domain/entities/index.js +19 -0
- package/dist/domain/entities/post-collection.entity.d.ts +33 -0
- package/dist/domain/entities/post-collection.entity.js +70 -0
- package/dist/domain/entities/product-collection.entity.d.ts +30 -0
- package/dist/domain/entities/product-collection.entity.js +55 -0
- package/dist/domain/index.d.ts +6 -0
- package/dist/domain/index.js +22 -0
- package/dist/domain/mappers/collection.mapper.d.ts +11 -0
- package/dist/domain/mappers/collection.mapper.js +56 -0
- package/dist/domain/mappers/index.d.ts +3 -0
- package/dist/domain/mappers/index.js +19 -0
- package/dist/domain/mappers/post-collection.mapper.d.ts +11 -0
- package/dist/domain/mappers/post-collection.mapper.js +50 -0
- package/dist/domain/mappers/product-collection.mapper.d.ts +11 -0
- package/dist/domain/mappers/product-collection.mapper.js +48 -0
- package/dist/domain/repositories/collection.repository.d.ts +21 -0
- package/dist/domain/repositories/collection.repository.js +93 -0
- package/dist/domain/repositories/index.d.ts +3 -0
- package/dist/domain/repositories/index.js +19 -0
- package/dist/domain/repositories/post-collection.repository.d.ts +21 -0
- package/dist/domain/repositories/post-collection.repository.js +107 -0
- package/dist/domain/repositories/product-collection.repository.d.ts +21 -0
- package/dist/domain/repositories/product-collection.repository.js +98 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +23 -0
- package/dist/infra/daos/collection.dao.d.ts +7 -0
- package/dist/infra/daos/collection.dao.js +36 -0
- package/dist/infra/daos/index.d.ts +3 -0
- package/dist/infra/daos/index.js +19 -0
- package/dist/infra/daos/post-collection.dao.d.ts +10 -0
- package/dist/infra/daos/post-collection.dao.js +70 -0
- package/dist/infra/daos/product-collection.dao.d.ts +9 -0
- package/dist/infra/daos/product-collection.dao.js +69 -0
- package/dist/infra/event-handlers/collection.event-emitter.d.ts +6 -0
- package/dist/infra/event-handlers/collection.event-emitter.js +27 -0
- package/dist/infra/event-handlers/index.d.ts +3 -0
- package/dist/infra/event-handlers/index.js +19 -0
- package/dist/infra/event-handlers/post-collection.event-emitter.d.ts +6 -0
- package/dist/infra/event-handlers/post-collection.event-emitter.js +27 -0
- package/dist/infra/event-handlers/product-collection.event-emitter.d.ts +6 -0
- package/dist/infra/event-handlers/product-collection.event-emitter.js +27 -0
- package/dist/infra/filters/collection.filter.d.ts +25 -0
- package/dist/infra/filters/collection.filter.js +84 -0
- package/dist/infra/filters/index.d.ts +3 -0
- package/dist/infra/filters/index.js +19 -0
- package/dist/infra/filters/post-collection.filter.d.ts +16 -0
- package/dist/infra/filters/post-collection.filter.js +54 -0
- package/dist/infra/filters/product-collection.filter.d.ts +13 -0
- package/dist/infra/filters/product-collection.filter.js +44 -0
- package/dist/infra/index.d.ts +6 -0
- package/dist/infra/index.js +22 -0
- package/dist/infra/mappers/collection.mapper.d.ts +8 -0
- package/dist/infra/mappers/collection.mapper.js +31 -0
- package/dist/infra/mappers/index.d.ts +3 -0
- package/dist/infra/mappers/index.js +19 -0
- package/dist/infra/mappers/post-collection.mapper.d.ts +8 -0
- package/dist/infra/mappers/post-collection.mapper.js +25 -0
- package/dist/infra/mappers/product-collection.mapper.d.ts +8 -0
- package/dist/infra/mappers/product-collection.mapper.js +24 -0
- package/dist/infra/query-configs/collection.query-config.d.ts +3 -0
- package/dist/infra/query-configs/collection.query-config.js +46 -0
- package/dist/infra/query-configs/index.d.ts +3 -0
- package/dist/infra/query-configs/index.js +19 -0
- package/dist/infra/query-configs/post-collection.query-config.d.ts +3 -0
- package/dist/infra/query-configs/post-collection.query-config.js +31 -0
- package/dist/infra/query-configs/product-collection.query-config.d.ts +3 -0
- package/dist/infra/query-configs/product-collection.query-config.js +26 -0
- package/dist/infra/records/collection.record.d.ts +11 -0
- package/dist/infra/records/collection.record.js +2 -0
- package/dist/infra/records/index.d.ts +3 -0
- package/dist/infra/records/index.js +19 -0
- package/dist/infra/records/post-collection.record.d.ts +7 -0
- package/dist/infra/records/post-collection.record.js +2 -0
- package/dist/infra/records/product-collection.record.d.ts +7 -0
- package/dist/infra/records/product-collection.record.js +2 -0
- package/dist/presentation/controllers/index.d.ts +2 -0
- package/dist/presentation/controllers/index.js +18 -0
- package/dist/presentation/controllers/internals/index.d.ts +1 -0
- package/dist/presentation/controllers/internals/index.js +17 -0
- package/dist/presentation/controllers/internals/product-collection.internal.rest.d.ts +8 -0
- package/dist/presentation/controllers/internals/product-collection.internal.rest.js +45 -0
- package/dist/presentation/controllers/storefront/collection.storefront.rest.d.ts +26 -0
- package/dist/presentation/controllers/storefront/collection.storefront.rest.js +155 -0
- package/dist/presentation/controllers/storefront/index.d.ts +3 -0
- package/dist/presentation/controllers/storefront/index.js +19 -0
- package/dist/presentation/controllers/storefront/post-collection.storefront.d.ts +7 -0
- package/dist/presentation/controllers/storefront/post-collection.storefront.js +37 -0
- package/dist/presentation/controllers/storefront/product-collection.storefront.rest.d.ts +5 -0
- package/dist/presentation/controllers/storefront/product-collection.storefront.rest.js +50 -0
- package/dist/presentation/index.d.ts +1 -0
- package/dist/presentation/index.js +17 -0
- package/dist/shared/configs/index.d.ts +1 -0
- package/dist/shared/configs/index.js +17 -0
- package/dist/shared/configs/pagination.config.d.ts +4 -0
- package/dist/shared/configs/pagination.config.js +7 -0
- package/dist/shared/constants/collection-inject-tokens.const.d.ts +56 -0
- package/dist/shared/constants/collection-inject-tokens.const.js +61 -0
- package/dist/shared/constants/collection-table-names.const.d.ts +12 -0
- package/dist/shared/constants/collection-table-names.const.js +16 -0
- package/dist/shared/constants/component-inject-tokens.const.d.ts +7 -0
- package/dist/shared/constants/component-inject-tokens.const.js +11 -0
- package/dist/shared/constants/error-codes.const.d.ts +6 -0
- package/dist/shared/constants/error-codes.const.js +10 -0
- package/dist/shared/constants/index.d.ts +4 -0
- package/dist/shared/constants/index.js +21 -0
- package/dist/shared/core/filter.d.ts +80 -0
- package/dist/shared/core/filter.js +554 -0
- package/dist/shared/core/index.d.ts +1 -0
- package/dist/shared/core/index.js +17 -0
- package/dist/shared/index.d.ts +5 -0
- package/dist/shared/index.js +21 -0
- package/dist/shared/interfaces/ambassador-dao.interface.d.ts +5 -0
- package/dist/shared/interfaces/ambassador-dao.interface.js +2 -0
- package/dist/shared/interfaces/ambassador-usecase.interface.d.ts +16 -0
- package/dist/shared/interfaces/ambassador-usecase.interface.js +2 -0
- package/dist/shared/interfaces/campaign-service.interface.d.ts +3 -0
- package/dist/shared/interfaces/campaign-service.interface.js +4 -0
- package/dist/shared/interfaces/index.d.ts +6 -0
- package/dist/shared/interfaces/index.js +22 -0
- package/dist/shared/interfaces/post-product-dao.interface.d.ts +8 -0
- package/dist/shared/interfaces/post-product-dao.interface.js +2 -0
- package/dist/shared/interfaces/product-service.interface.d.ts +6 -0
- package/dist/shared/interfaces/product-service.interface.js +2 -0
- package/dist/shared/interfaces/ugc-management-service.interface.d.ts +11 -0
- package/dist/shared/interfaces/ugc-management-service.interface.js +2 -0
- package/dist/shared/types/common.type.d.ts +4 -0
- package/dist/shared/types/common.type.js +2 -0
- package/dist/shared/types/discount.enum.d.ts +4 -0
- package/dist/shared/types/discount.enum.js +8 -0
- package/dist/shared/types/index.d.ts +4 -0
- package/dist/shared/types/index.js +20 -0
- package/dist/shared/types/shopify.type.d.ts +28 -0
- package/dist/shared/types/shopify.type.js +2 -0
- package/dist/shared/types/ugc.type.d.ts +41 -0
- package/dist/shared/types/ugc.type.js +2 -0
- package/package.json +56 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { IUseCase, UseCase, UseCaseContext } from '@cbidigital/aqua-ddd';
|
|
2
|
+
import { CollectionRepository, UpdateCollectionInput } from '../../../domain';
|
|
3
|
+
export type UpdateCollectionUseCaseInput = UpdateCollectionInput;
|
|
4
|
+
export type UpdateCollectionUseCaseOutput = {
|
|
5
|
+
id: string;
|
|
6
|
+
};
|
|
7
|
+
export type IUpdateCollectionUseCase = IUseCase<UpdateCollectionUseCaseInput, UpdateCollectionUseCaseOutput, UseCaseContext>;
|
|
8
|
+
export declare class CollectionUpdateUseCase<I extends UpdateCollectionUseCaseInput = UpdateCollectionUseCaseInput, O extends UpdateCollectionUseCaseOutput = UpdateCollectionUseCaseOutput, C extends UseCaseContext = UseCaseContext> extends UseCase<I, O, C> implements IUpdateCollectionUseCase {
|
|
9
|
+
protected readonly collectionRepository: CollectionRepository;
|
|
10
|
+
private readonly logger;
|
|
11
|
+
constructor(collectionRepository: CollectionRepository);
|
|
12
|
+
processing: (input: UpdateCollectionUseCaseInput) => Promise<{
|
|
13
|
+
id: string;
|
|
14
|
+
}>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.CollectionUpdateUseCase = void 0;
|
|
16
|
+
const aqua_ddd_1 = require("@cbidigital/aqua-ddd");
|
|
17
|
+
const common_1 = require("@heronjs/common");
|
|
18
|
+
const shared_1 = require("../../../shared");
|
|
19
|
+
const domain_1 = require("../../../domain");
|
|
20
|
+
const zod_1 = require("zod");
|
|
21
|
+
const UpdateCollectionUseCaseInputSchema = zod_1.z.object({
|
|
22
|
+
id: zod_1.z.string().uuid(),
|
|
23
|
+
ambassadorId: zod_1.z.string(),
|
|
24
|
+
collectionName: zod_1.z.string().optional(),
|
|
25
|
+
description: zod_1.z.string().optional(),
|
|
26
|
+
isFavorite: zod_1.z.boolean().default(false),
|
|
27
|
+
});
|
|
28
|
+
let CollectionUpdateUseCase = class CollectionUpdateUseCase extends aqua_ddd_1.UseCase {
|
|
29
|
+
constructor(collectionRepository) {
|
|
30
|
+
super();
|
|
31
|
+
this.collectionRepository = collectionRepository;
|
|
32
|
+
// send message to create post
|
|
33
|
+
this.processing = async (input) => {
|
|
34
|
+
if (!input) {
|
|
35
|
+
throw new common_1.RuntimeError('UPDATE_COLLECTION', shared_1.ERROR_CODES.BAD_REQUEST, 'Invalid payload');
|
|
36
|
+
}
|
|
37
|
+
const model = UpdateCollectionUseCaseInputSchema.parse(input);
|
|
38
|
+
// check if post already exists
|
|
39
|
+
const entity = await this.collectionRepository.findOne({
|
|
40
|
+
filter: {
|
|
41
|
+
id: { $eq: model.id },
|
|
42
|
+
ambassadorId: { $eq: model.ambassadorId },
|
|
43
|
+
},
|
|
44
|
+
}, {
|
|
45
|
+
tenantId: this.context.tenantId,
|
|
46
|
+
});
|
|
47
|
+
if (!entity?.id) {
|
|
48
|
+
throw new common_1.RuntimeError('UPDATE_COLLECTION', shared_1.ERROR_CODES.NOT_FOUND, 'Collection not found');
|
|
49
|
+
}
|
|
50
|
+
if (entity.collectionType !== domain_1.CollectionTypeEnum.OTHERS) {
|
|
51
|
+
throw new common_1.RuntimeError('DELETE_COLLECTION', shared_1.ERROR_CODES.NOT_FOUND, 'Cannot update default collections');
|
|
52
|
+
}
|
|
53
|
+
await entity.update(input);
|
|
54
|
+
await this.collectionRepository.update(entity, {
|
|
55
|
+
tenantId: this.context.tenantId,
|
|
56
|
+
});
|
|
57
|
+
return {
|
|
58
|
+
id: entity.id,
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
this.logger = new common_1.Logger(this.constructor.name);
|
|
62
|
+
this.setMethods(this.processing);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
CollectionUpdateUseCase = __decorate([
|
|
66
|
+
(0, common_1.Provider)({
|
|
67
|
+
token: shared_1.COLLECTION_INJECT_TOKENS.USECASE.COLLECTION_UPDATE,
|
|
68
|
+
scope: common_1.Lifecycle.Transient,
|
|
69
|
+
}),
|
|
70
|
+
__param(0, (0, common_1.Inject)(shared_1.COLLECTION_INJECT_TOKENS.REPOSITORY.COLLECTION)),
|
|
71
|
+
__metadata("design:paramtypes", [domain_1.CollectionRepository])
|
|
72
|
+
], CollectionUpdateUseCase);
|
|
73
|
+
exports.CollectionUpdateUseCase = CollectionUpdateUseCase;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./command"), exports);
|
|
18
|
+
__exportStar(require("./query"), exports);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { IUseCase, PaginationInput, SortInput, UseCase, UseCaseContext } from '@cbidigital/aqua-ddd';
|
|
2
|
+
import type { ShopifyProduct, UGCPost, AmbassadorDto, IProductService, IUgcManagementService, IGetAmbassadorByIdUseCase, IPostProductDao } from '../../../shared';
|
|
3
|
+
import { CollectionDto } from '../../../domain';
|
|
4
|
+
import { CollectionDao, PostCollectionDao, ProductCollectionDao } from '../../../infra';
|
|
5
|
+
type GetDetailCollectionUseCaseInput = PaginationInput & {
|
|
6
|
+
id: string;
|
|
7
|
+
needLinkedProduct?: boolean;
|
|
8
|
+
};
|
|
9
|
+
type GetDetailCollectionUseCaseOutput = {
|
|
10
|
+
collection: Partial<CollectionDto>;
|
|
11
|
+
totalCount: number;
|
|
12
|
+
posts: UGCPost[];
|
|
13
|
+
products: ShopifyProduct[];
|
|
14
|
+
};
|
|
15
|
+
export type IGetDetailCollectionUseCase = IUseCase<GetDetailCollectionUseCaseInput, GetDetailCollectionUseCaseOutput, UseCaseContext>;
|
|
16
|
+
export declare class CollectionDetailUseCase<I extends GetDetailCollectionUseCaseInput = GetDetailCollectionUseCaseInput, O extends GetDetailCollectionUseCaseOutput = GetDetailCollectionUseCaseOutput, C extends UseCaseContext = UseCaseContext> extends UseCase<I, O, C> implements IGetDetailCollectionUseCase {
|
|
17
|
+
protected readonly collectionDao: CollectionDao;
|
|
18
|
+
protected readonly productCollectionDao: ProductCollectionDao;
|
|
19
|
+
protected readonly postCollectionDao: PostCollectionDao;
|
|
20
|
+
protected readonly ugcManagementService: IUgcManagementService;
|
|
21
|
+
protected readonly productService: IProductService;
|
|
22
|
+
protected readonly getAbsByIdUsecase: IGetAmbassadorByIdUseCase;
|
|
23
|
+
protected readonly postProductDao: IPostProductDao;
|
|
24
|
+
private readonly logger;
|
|
25
|
+
constructor(collectionDao: CollectionDao, productCollectionDao: ProductCollectionDao, postCollectionDao: PostCollectionDao, ugcManagementService: IUgcManagementService, productService: IProductService, getAbsByIdUsecase: IGetAmbassadorByIdUseCase, postProductDao: IPostProductDao);
|
|
26
|
+
processing: (input: GetDetailCollectionUseCaseInput) => Promise<GetDetailCollectionUseCaseOutput>;
|
|
27
|
+
handleGetPosts(collectionId: string, ambassador: Partial<AmbassadorDto>, limit?: number, offset?: number, sort?: SortInput, getAll?: boolean, needLinkedProduct?: boolean): Promise<{
|
|
28
|
+
posts: UGCPost[];
|
|
29
|
+
totalPostCount: number;
|
|
30
|
+
}>;
|
|
31
|
+
handleGetProducts(collectionId: string, ambassador: Partial<AmbassadorDto>, limit?: number, offset?: number, sort?: SortInput, getAll?: boolean): Promise<{
|
|
32
|
+
products: ShopifyProduct[];
|
|
33
|
+
totalProductCount: number;
|
|
34
|
+
}>;
|
|
35
|
+
}
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,216 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.CollectionDetailUseCase = void 0;
|
|
16
|
+
const aqua_ddd_1 = require("@cbidigital/aqua-ddd");
|
|
17
|
+
const common_1 = require("@heronjs/common");
|
|
18
|
+
const shared_1 = require("../../../shared");
|
|
19
|
+
const domain_1 = require("../../../domain");
|
|
20
|
+
const infra_1 = require("../../../infra");
|
|
21
|
+
let CollectionDetailUseCase = class CollectionDetailUseCase extends aqua_ddd_1.UseCase {
|
|
22
|
+
constructor(collectionDao, productCollectionDao, postCollectionDao, ugcManagementService, productService, getAbsByIdUsecase, postProductDao) {
|
|
23
|
+
super();
|
|
24
|
+
this.collectionDao = collectionDao;
|
|
25
|
+
this.productCollectionDao = productCollectionDao;
|
|
26
|
+
this.postCollectionDao = postCollectionDao;
|
|
27
|
+
this.ugcManagementService = ugcManagementService;
|
|
28
|
+
this.productService = productService;
|
|
29
|
+
this.getAbsByIdUsecase = getAbsByIdUsecase;
|
|
30
|
+
this.postProductDao = postProductDao;
|
|
31
|
+
this.processing = async (input) => {
|
|
32
|
+
try {
|
|
33
|
+
const getAll = true;
|
|
34
|
+
const { id, limit, offset, sort, needLinkedProduct = false } = input;
|
|
35
|
+
const collection = await this.collectionDao.findOne({ filter: { id: { $eq: id } } });
|
|
36
|
+
if (!collection) {
|
|
37
|
+
throw new common_1.RuntimeError(this.constructor.name, shared_1.ERROR_CODES.NOT_FOUND, 'Collection not found');
|
|
38
|
+
}
|
|
39
|
+
const absId = collection?.ambassadorId || '';
|
|
40
|
+
const ambassador = await this.getAbsByIdUsecase.exec({ id: absId });
|
|
41
|
+
if (!ambassador)
|
|
42
|
+
throw new common_1.RuntimeError('GET_DETAIL_COLLECTION', shared_1.ERROR_CODES.NOT_FOUND, 'Ambassador not found');
|
|
43
|
+
const response = {
|
|
44
|
+
collection: collection,
|
|
45
|
+
totalCount: 0,
|
|
46
|
+
posts: [],
|
|
47
|
+
products: [],
|
|
48
|
+
};
|
|
49
|
+
if (collection.collectionType === domain_1.CollectionTypeEnum.ALL) {
|
|
50
|
+
const [allPosts, allProducts] = await Promise.all([
|
|
51
|
+
this.handleGetPosts(id, ambassador, limit, offset, sort, getAll, false),
|
|
52
|
+
this.handleGetProducts(id, ambassador, limit, offset, sort, getAll),
|
|
53
|
+
]);
|
|
54
|
+
response.posts = allPosts.posts;
|
|
55
|
+
response.products = allProducts.products;
|
|
56
|
+
response.totalCount = Number(allPosts.totalPostCount + allProducts.totalProductCount);
|
|
57
|
+
}
|
|
58
|
+
else if (collection.collectionType === domain_1.CollectionTypeEnum.POSTS) {
|
|
59
|
+
const allPosts = await this.handleGetPosts(id, ambassador, limit, offset, sort, getAll, needLinkedProduct);
|
|
60
|
+
response.posts = allPosts.posts;
|
|
61
|
+
response.totalCount = allPosts.totalPostCount;
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
const [posts, products] = await Promise.all([
|
|
65
|
+
this.handleGetPosts(id, ambassador, limit, offset, sort),
|
|
66
|
+
this.handleGetProducts(id, ambassador, limit, offset, sort),
|
|
67
|
+
]);
|
|
68
|
+
response.posts = posts.posts;
|
|
69
|
+
response.products = products.products;
|
|
70
|
+
response.totalCount = Number(posts.totalPostCount + products.totalProductCount);
|
|
71
|
+
}
|
|
72
|
+
return response;
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
throw new common_1.RuntimeError('GET_DETAIL_COLLECTION', shared_1.ERROR_CODES.BAD_REQUEST, error);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
this.logger = new common_1.Logger(this.constructor.name);
|
|
79
|
+
this.setMethods(this.processing);
|
|
80
|
+
}
|
|
81
|
+
async handleGetPosts(collectionId, ambassador, limit = 30, offset = 0, sort, getAll = false, needLinkedProduct = true) {
|
|
82
|
+
const emptyResponse = {
|
|
83
|
+
posts: [],
|
|
84
|
+
totalPostCount: 0,
|
|
85
|
+
};
|
|
86
|
+
try {
|
|
87
|
+
const postsLinkedProducts = await this.postCollectionDao.findPostsLinkedProduct(collectionId);
|
|
88
|
+
const collectionPostsConfig = await this.postCollectionDao.find({
|
|
89
|
+
filter: { ambassadorId: { $eq: ambassador?.id ?? '' } },
|
|
90
|
+
});
|
|
91
|
+
let postIds = postsLinkedProducts.flatMap((p) => typeof p.postId === 'string' ? [p.postId] : []);
|
|
92
|
+
if (!getAll && !postIds.length) {
|
|
93
|
+
return emptyResponse;
|
|
94
|
+
}
|
|
95
|
+
const absSocialUsername = ambassador.ambassadorMetric?.map((metric) => metric.socialUsername || '');
|
|
96
|
+
let listPostResponse;
|
|
97
|
+
try {
|
|
98
|
+
listPostResponse = getAll
|
|
99
|
+
? await this.ugcManagementService.getApprovedPosts({
|
|
100
|
+
absUsernames: absSocialUsername,
|
|
101
|
+
paginationInput: { limit, offset, sort },
|
|
102
|
+
})
|
|
103
|
+
: await this.ugcManagementService.getApprovedPosts({
|
|
104
|
+
ids: postIds,
|
|
105
|
+
paginationInput: { limit, offset, sort },
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
this.logger.error('Get Posts', error);
|
|
110
|
+
return emptyResponse;
|
|
111
|
+
}
|
|
112
|
+
const configMap = Object.fromEntries(collectionPostsConfig.map((cfg) => [cfg.postId, cfg]));
|
|
113
|
+
let filteredPosts = listPostResponse.items;
|
|
114
|
+
postIds = filteredPosts.map((item) => item.id);
|
|
115
|
+
const postHasProduct = await this.postProductDao.find({
|
|
116
|
+
filter: {
|
|
117
|
+
postId: { $in: postIds },
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
const postHasProductMap = {};
|
|
121
|
+
postHasProduct.forEach((item) => {
|
|
122
|
+
if (item.postId)
|
|
123
|
+
postHasProductMap[item.postId] = true;
|
|
124
|
+
});
|
|
125
|
+
// need filter only post has product
|
|
126
|
+
if (needLinkedProduct) {
|
|
127
|
+
filteredPosts = filteredPosts.filter((post) => !!postHasProductMap[post.id]);
|
|
128
|
+
}
|
|
129
|
+
const posts = filteredPosts.map((post) => {
|
|
130
|
+
return {
|
|
131
|
+
...post,
|
|
132
|
+
hidden: configMap[post.id]?.hidden ?? false,
|
|
133
|
+
collectionId: configMap[post.id]?.collectionId || '',
|
|
134
|
+
hasProduct: !!postHasProductMap[post.id],
|
|
135
|
+
};
|
|
136
|
+
});
|
|
137
|
+
return {
|
|
138
|
+
posts: posts,
|
|
139
|
+
totalPostCount: Number(posts.length),
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
throw error;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
async handleGetProducts(collectionId, ambassador, limit = 30, offset = 0, sort, getAll = false) {
|
|
147
|
+
try {
|
|
148
|
+
const emptyResponse = {
|
|
149
|
+
products: [],
|
|
150
|
+
totalProductCount: 0,
|
|
151
|
+
};
|
|
152
|
+
const filter = getAll
|
|
153
|
+
? { ambassadorId: { $eq: ambassador.id } }
|
|
154
|
+
: { collectionId: { $eq: collectionId } };
|
|
155
|
+
const collectionProducts = await this.productCollectionDao.find({
|
|
156
|
+
filter: filter,
|
|
157
|
+
sort,
|
|
158
|
+
});
|
|
159
|
+
const productIds = collectionProducts.flatMap((p) => typeof p.productId === 'string' ? [p.productId] : []);
|
|
160
|
+
if (productIds.length == 0)
|
|
161
|
+
return emptyResponse;
|
|
162
|
+
const { items, totalCount } = await this.productService.getProducts({
|
|
163
|
+
limit,
|
|
164
|
+
offset,
|
|
165
|
+
}, productIds);
|
|
166
|
+
const discountValue = ambassador.ambassadorDiscountValue;
|
|
167
|
+
const discountType = ambassador.ambassadorDiscountValueType;
|
|
168
|
+
const collectionProductMap = new Map(collectionProducts.map((p) => [p.productId, p]));
|
|
169
|
+
const products = items.map((product) => {
|
|
170
|
+
const maxValue = Number(product.productMaxPrice) ?? 0;
|
|
171
|
+
const discount = discountValue ?? 0;
|
|
172
|
+
let minValue = Number(product.productMinPrice) ?? 0;
|
|
173
|
+
if (discountType === shared_1.DiscountValueType.PERCENTAGE) {
|
|
174
|
+
minValue = maxValue - (maxValue * discount) / 100;
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
minValue = maxValue - discount;
|
|
178
|
+
}
|
|
179
|
+
if (minValue < 0)
|
|
180
|
+
minValue = 0;
|
|
181
|
+
const collectionProduct = collectionProductMap.get(product.id);
|
|
182
|
+
return {
|
|
183
|
+
productId: product.id,
|
|
184
|
+
...product,
|
|
185
|
+
productMinPrice: minValue,
|
|
186
|
+
productMaxPrice: maxValue,
|
|
187
|
+
id: collectionProduct?.id ?? '',
|
|
188
|
+
};
|
|
189
|
+
});
|
|
190
|
+
return {
|
|
191
|
+
products: products,
|
|
192
|
+
totalProductCount: Number(totalCount),
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
catch (error) {
|
|
196
|
+
throw error;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
CollectionDetailUseCase = __decorate([
|
|
201
|
+
(0, common_1.Provider)({
|
|
202
|
+
token: shared_1.COLLECTION_INJECT_TOKENS.USECASE.COLLECTION_GET_DETAIL,
|
|
203
|
+
scope: common_1.Lifecycle.Transient,
|
|
204
|
+
}),
|
|
205
|
+
__param(0, (0, common_1.Inject)(shared_1.COLLECTION_INJECT_TOKENS.DAO.COLLECTION)),
|
|
206
|
+
__param(1, (0, common_1.Inject)(shared_1.COLLECTION_INJECT_TOKENS.DAO.PRODUCT_COLLECTION)),
|
|
207
|
+
__param(2, (0, common_1.Inject)(shared_1.COLLECTION_INJECT_TOKENS.DAO.POST_COLLECTION)),
|
|
208
|
+
__param(3, (0, common_1.Inject)(shared_1.COMPONENT_INJECT_TOKENS.SERVICE.UGC_MANAGEMENT_SERVICE)),
|
|
209
|
+
__param(4, (0, common_1.Inject)(shared_1.COMPONENT_INJECT_TOKENS.SERVICE.PRODUCT_SERVICE)),
|
|
210
|
+
__param(5, (0, common_1.Inject)(shared_1.COLLECTION_INJECT_TOKENS.USECASE.GET_AMBASSADOR_BY_ID)),
|
|
211
|
+
__param(6, (0, common_1.Inject)(shared_1.COLLECTION_INJECT_TOKENS.DAO.POST_PRODUCT)),
|
|
212
|
+
__metadata("design:paramtypes", [infra_1.CollectionDao,
|
|
213
|
+
infra_1.ProductCollectionDao,
|
|
214
|
+
infra_1.PostCollectionDao, Object, Object, Object, Object])
|
|
215
|
+
], CollectionDetailUseCase);
|
|
216
|
+
exports.CollectionDetailUseCase = CollectionDetailUseCase;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { IUseCase, PaginationInput, UseCase, UseCaseContext } from '@cbidigital/aqua-ddd';
|
|
2
|
+
import { CollectionDto } from '../../../domain';
|
|
3
|
+
import { CollectionDao } from '../../../infra';
|
|
4
|
+
import { IGetDetailCollectionUseCase } from './get-detail-collection.usecase';
|
|
5
|
+
type GetListCollectionUseCaseInput = PaginationInput<CollectionDto> & {
|
|
6
|
+
ambassadorId?: string;
|
|
7
|
+
};
|
|
8
|
+
type GetListCollectionUseCaseOutput = {
|
|
9
|
+
totalCount: number;
|
|
10
|
+
items: Partial<CollectionDto>[];
|
|
11
|
+
};
|
|
12
|
+
export type IGetListCollectionUseCase = IUseCase<GetListCollectionUseCaseInput, GetListCollectionUseCaseOutput, UseCaseContext>;
|
|
13
|
+
export declare class CollectionListUseCase<I extends GetListCollectionUseCaseInput = GetListCollectionUseCaseInput, O extends GetListCollectionUseCaseOutput = GetListCollectionUseCaseOutput, C extends UseCaseContext = UseCaseContext> extends UseCase<I, O, C> implements IGetListCollectionUseCase {
|
|
14
|
+
protected readonly collectionDao: CollectionDao;
|
|
15
|
+
protected readonly getDetailCollectionUsecase: IGetDetailCollectionUseCase;
|
|
16
|
+
constructor(collectionDao: CollectionDao, getDetailCollectionUsecase: IGetDetailCollectionUseCase);
|
|
17
|
+
processing: (input: GetListCollectionUseCaseInput) => Promise<{
|
|
18
|
+
totalCount: number;
|
|
19
|
+
items: Partial<CollectionDto>[];
|
|
20
|
+
}>;
|
|
21
|
+
sortCollections(collections: Partial<CollectionDto>[]): Partial<CollectionDto>[];
|
|
22
|
+
}
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,96 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.CollectionListUseCase = void 0;
|
|
16
|
+
const aqua_ddd_1 = require("@cbidigital/aqua-ddd");
|
|
17
|
+
const common_1 = require("@heronjs/common");
|
|
18
|
+
const shared_1 = require("../../../shared");
|
|
19
|
+
const domain_1 = require("../../../domain");
|
|
20
|
+
const infra_1 = require("../../../infra");
|
|
21
|
+
let CollectionListUseCase = class CollectionListUseCase extends aqua_ddd_1.UseCase {
|
|
22
|
+
constructor(collectionDao, getDetailCollectionUsecase) {
|
|
23
|
+
super();
|
|
24
|
+
this.collectionDao = collectionDao;
|
|
25
|
+
this.getDetailCollectionUsecase = getDetailCollectionUsecase;
|
|
26
|
+
this.processing = async (input) => {
|
|
27
|
+
const { ambassadorId } = input;
|
|
28
|
+
const [totalCount, items] = await Promise.all([
|
|
29
|
+
this.collectionDao.count(input, {
|
|
30
|
+
tenantId: this.context.tenantId,
|
|
31
|
+
}),
|
|
32
|
+
this.collectionDao.find(input, {
|
|
33
|
+
tenantId: this.context.tenantId,
|
|
34
|
+
}),
|
|
35
|
+
]);
|
|
36
|
+
if (!!ambassadorId) {
|
|
37
|
+
return {
|
|
38
|
+
totalCount,
|
|
39
|
+
items: this.sortCollections(items),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
const postCollection = items.find((col) => col.collectionType === domain_1.CollectionTypeEnum.POSTS);
|
|
43
|
+
if (!postCollection?.id) {
|
|
44
|
+
return {
|
|
45
|
+
totalCount,
|
|
46
|
+
items: this.sortCollections(items),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
const collectionPosts = await this.getDetailCollectionUsecase.exec({
|
|
50
|
+
id: postCollection?.id,
|
|
51
|
+
needLinkedProduct: true,
|
|
52
|
+
});
|
|
53
|
+
const filteredItems = collectionPosts.posts.length === 0
|
|
54
|
+
? items.filter((col) => col.id !== collectionPosts.collection.id)
|
|
55
|
+
: items;
|
|
56
|
+
return {
|
|
57
|
+
totalCount,
|
|
58
|
+
items: this.sortCollections(filteredItems),
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
this.setMethods(this.processing);
|
|
62
|
+
}
|
|
63
|
+
sortCollections(collections) {
|
|
64
|
+
const order = {
|
|
65
|
+
[domain_1.CollectionTypeEnum.ALL]: 0,
|
|
66
|
+
[domain_1.CollectionTypeEnum.POSTS]: 1,
|
|
67
|
+
[domain_1.CollectionTypeEnum.OTHERS]: 2,
|
|
68
|
+
};
|
|
69
|
+
return collections.sort((a, b) => {
|
|
70
|
+
const aType = a.collectionType ?? domain_1.CollectionTypeEnum.OTHERS;
|
|
71
|
+
const bType = b.collectionType ?? domain_1.CollectionTypeEnum.OTHERS;
|
|
72
|
+
const aOrder = order[aType] ?? 2;
|
|
73
|
+
const bOrder = order[bType] ?? 2;
|
|
74
|
+
if (aOrder !== bOrder) {
|
|
75
|
+
return aOrder - bOrder;
|
|
76
|
+
}
|
|
77
|
+
// Ưu tiên isFavorite === true
|
|
78
|
+
if (a.isFavorite !== b.isFavorite) {
|
|
79
|
+
return b.isFavorite ? 1 : -1;
|
|
80
|
+
}
|
|
81
|
+
const aDate = a.createdAt ? new Date(a.createdAt).getTime() : 0;
|
|
82
|
+
const bDate = b.createdAt ? new Date(b.createdAt).getTime() : 0;
|
|
83
|
+
return bDate - aDate;
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
CollectionListUseCase = __decorate([
|
|
88
|
+
(0, common_1.Provider)({
|
|
89
|
+
token: shared_1.COLLECTION_INJECT_TOKENS.USECASE.COLLECTION_GET_LIST,
|
|
90
|
+
scope: common_1.Lifecycle.Transient,
|
|
91
|
+
}),
|
|
92
|
+
__param(0, (0, common_1.Inject)(shared_1.COLLECTION_INJECT_TOKENS.DAO.COLLECTION)),
|
|
93
|
+
__param(1, (0, common_1.Inject)(shared_1.COLLECTION_INJECT_TOKENS.USECASE.COLLECTION_GET_DETAIL)),
|
|
94
|
+
__metadata("design:paramtypes", [infra_1.CollectionDao, Object])
|
|
95
|
+
], CollectionListUseCase);
|
|
96
|
+
exports.CollectionListUseCase = CollectionListUseCase;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { IUseCase, PaginationInput, UseCase, UseCaseContext } from '@cbidigital/aqua-ddd';
|
|
2
|
+
import { CollectionDao, ProductCollectionDao } from '../../../infra';
|
|
3
|
+
import { ProductCollectionDto } from '../../../domain';
|
|
4
|
+
type GetProductsByCollectionInternalUseCaseInput = PaginationInput<ProductCollectionDto>;
|
|
5
|
+
type GetProductsByCollectionInternalUseCaseOutput = {
|
|
6
|
+
totalCount: number;
|
|
7
|
+
items: Partial<ProductCollectionDto>[];
|
|
8
|
+
};
|
|
9
|
+
export type IGetProductsByCollectionInternalUseCase = IUseCase<GetProductsByCollectionInternalUseCaseInput, GetProductsByCollectionInternalUseCaseOutput, UseCaseContext>;
|
|
10
|
+
export declare class GetProductsByCollectionInternalUseCase<I extends GetProductsByCollectionInternalUseCaseInput = GetProductsByCollectionInternalUseCaseInput, O extends GetProductsByCollectionInternalUseCaseOutput = GetProductsByCollectionInternalUseCaseOutput, C extends UseCaseContext = UseCaseContext> extends UseCase<I, O, C> implements IGetProductsByCollectionInternalUseCase {
|
|
11
|
+
protected readonly productCollectionDao: ProductCollectionDao;
|
|
12
|
+
protected readonly collectionDao: CollectionDao;
|
|
13
|
+
constructor(productCollectionDao: ProductCollectionDao, collectionDao: CollectionDao);
|
|
14
|
+
processing: (input: GetProductsByCollectionInternalUseCaseInput) => Promise<{
|
|
15
|
+
totalCount: number;
|
|
16
|
+
items: ProductCollectionDto[];
|
|
17
|
+
}>;
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,65 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.GetProductsByCollectionInternalUseCase = void 0;
|
|
16
|
+
const aqua_ddd_1 = require("@cbidigital/aqua-ddd");
|
|
17
|
+
const common_1 = require("@heronjs/common");
|
|
18
|
+
const shared_1 = require("../../../shared");
|
|
19
|
+
const infra_1 = require("../../../infra");
|
|
20
|
+
const domain_1 = require("../../../domain");
|
|
21
|
+
let GetProductsByCollectionInternalUseCase = class GetProductsByCollectionInternalUseCase extends aqua_ddd_1.UseCase {
|
|
22
|
+
constructor(productCollectionDao, collectionDao) {
|
|
23
|
+
super();
|
|
24
|
+
this.productCollectionDao = productCollectionDao;
|
|
25
|
+
this.collectionDao = collectionDao;
|
|
26
|
+
this.processing = async (input) => {
|
|
27
|
+
const { filter } = input;
|
|
28
|
+
const { collectionId: filterCollectionId } = filter || {};
|
|
29
|
+
if (filterCollectionId) {
|
|
30
|
+
const filterGetCollections = { id: filterCollectionId };
|
|
31
|
+
const collections = await this.collectionDao.find({
|
|
32
|
+
filter: filterGetCollections,
|
|
33
|
+
});
|
|
34
|
+
const existedAll = collections.find((col) => col.collectionType === domain_1.CollectionTypeEnum.ALL);
|
|
35
|
+
if (existedAll) {
|
|
36
|
+
input.filter = { ambassadorId: { $eq: existedAll.ambassadorId } };
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const [totalCount, items] = await Promise.all([
|
|
40
|
+
this.productCollectionDao.count(input, {
|
|
41
|
+
tenantId: this.context.tenantId,
|
|
42
|
+
}),
|
|
43
|
+
this.productCollectionDao.find(input, {
|
|
44
|
+
tenantId: this.context.tenantId,
|
|
45
|
+
}),
|
|
46
|
+
]);
|
|
47
|
+
return {
|
|
48
|
+
totalCount: Number(totalCount),
|
|
49
|
+
items: items,
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
this.setMethods(this.processing);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
GetProductsByCollectionInternalUseCase = __decorate([
|
|
56
|
+
(0, common_1.Provider)({
|
|
57
|
+
token: shared_1.COLLECTION_INJECT_TOKENS.USECASE.GET_PRODUCTS_BY_COLLECTIONS_INTERNAL,
|
|
58
|
+
scope: common_1.Lifecycle.Transient,
|
|
59
|
+
}),
|
|
60
|
+
__param(0, (0, common_1.Inject)(shared_1.COLLECTION_INJECT_TOKENS.DAO.PRODUCT_COLLECTION)),
|
|
61
|
+
__param(1, (0, common_1.Inject)(shared_1.COLLECTION_INJECT_TOKENS.DAO.COLLECTION)),
|
|
62
|
+
__metadata("design:paramtypes", [infra_1.ProductCollectionDao,
|
|
63
|
+
infra_1.CollectionDao])
|
|
64
|
+
], GetProductsByCollectionInternalUseCase);
|
|
65
|
+
exports.GetProductsByCollectionInternalUseCase = GetProductsByCollectionInternalUseCase;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { IUseCase, PaginationInput, UseCase, UseCaseContext } from '@cbidigital/aqua-ddd';
|
|
2
|
+
import type { ShopifyProduct, IProductService, IPostProductDao, IGetAmbassadorByIdUseCase } from '../../../shared';
|
|
3
|
+
import { CollectionDao, ProductCollectionDao } from '../../../infra';
|
|
4
|
+
type GetProductsByCollectionUseCaseInput = PaginationInput & {
|
|
5
|
+
ambassadorId: string;
|
|
6
|
+
};
|
|
7
|
+
type GetProductsByCollectionUseCaseOutput = {
|
|
8
|
+
totalCount: number;
|
|
9
|
+
items: Partial<ShopifyProduct>[];
|
|
10
|
+
};
|
|
11
|
+
export type IGetProductsByCollectionUseCase = IUseCase<GetProductsByCollectionUseCaseInput, GetProductsByCollectionUseCaseOutput, UseCaseContext>;
|
|
12
|
+
export declare class GetProductsByCollectionUseCase<I extends GetProductsByCollectionUseCaseInput = GetProductsByCollectionUseCaseInput, O extends GetProductsByCollectionUseCaseOutput = GetProductsByCollectionUseCaseOutput, C extends UseCaseContext = UseCaseContext> extends UseCase<I, O, C> implements IGetProductsByCollectionUseCase {
|
|
13
|
+
protected readonly collectionDao: CollectionDao;
|
|
14
|
+
protected readonly productCollectionDao: ProductCollectionDao;
|
|
15
|
+
protected readonly postProductDao: IPostProductDao;
|
|
16
|
+
protected readonly productService: IProductService;
|
|
17
|
+
protected readonly getAbsByIdUsecase: IGetAmbassadorByIdUseCase;
|
|
18
|
+
constructor(collectionDao: CollectionDao, productCollectionDao: ProductCollectionDao, postProductDao: IPostProductDao, productService: IProductService, getAbsByIdUsecase: IGetAmbassadorByIdUseCase);
|
|
19
|
+
processing: (input: GetProductsByCollectionUseCaseInput) => Promise<{
|
|
20
|
+
totalCount: number;
|
|
21
|
+
items: {
|
|
22
|
+
productMinPrice: number;
|
|
23
|
+
productMaxPrice: number;
|
|
24
|
+
id: string;
|
|
25
|
+
productId: string;
|
|
26
|
+
productName: string;
|
|
27
|
+
productShopifyId: string;
|
|
28
|
+
productUrl: string;
|
|
29
|
+
productDescription: string;
|
|
30
|
+
productImage: string;
|
|
31
|
+
productMedia: {
|
|
32
|
+
node: {
|
|
33
|
+
url: string;
|
|
34
|
+
};
|
|
35
|
+
}[];
|
|
36
|
+
productStatus: string;
|
|
37
|
+
createdAt: string;
|
|
38
|
+
updatedAt: string;
|
|
39
|
+
collectionId?: string | undefined;
|
|
40
|
+
collectionName: string;
|
|
41
|
+
}[];
|
|
42
|
+
}>;
|
|
43
|
+
}
|
|
44
|
+
export {};
|