@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,93 @@
|
|
|
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.CollectionRepository = 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
|
+
let CollectionRepository = class CollectionRepository extends aqua_ddd_1.BaseRepository {
|
|
21
|
+
constructor(db, collectionDao, collectionMapper) {
|
|
22
|
+
super({ db });
|
|
23
|
+
this.db = db;
|
|
24
|
+
this.collectionDao = collectionDao;
|
|
25
|
+
this.collectionMapper = collectionMapper;
|
|
26
|
+
}
|
|
27
|
+
async create(entity, options) {
|
|
28
|
+
await this.db.withTransaction(async (trx) => {
|
|
29
|
+
const dto = await this.collectionMapper.fromEntityToDto(entity);
|
|
30
|
+
await this.collectionDao.create(dto, { ...options, trx });
|
|
31
|
+
}, options);
|
|
32
|
+
entity.dispatchDomainEvents();
|
|
33
|
+
return entity;
|
|
34
|
+
}
|
|
35
|
+
async createList(entities, options) {
|
|
36
|
+
await this.db.withTransaction(async (trx) => {
|
|
37
|
+
const dtos = await this.collectionMapper.fromEntitiesToDtos(entities);
|
|
38
|
+
await this.collectionDao.createList(dtos, { ...options, trx });
|
|
39
|
+
}, options);
|
|
40
|
+
entities.forEach((entity) => entity.dispatchDomainEvents);
|
|
41
|
+
return entities;
|
|
42
|
+
}
|
|
43
|
+
async update(entity, options) {
|
|
44
|
+
await this.withTransaction(async (trx) => {
|
|
45
|
+
const dto = await this.collectionMapper.fromEntityToDto(entity);
|
|
46
|
+
await this.collectionDao.updateById(dto.id, dto, { ...options, trx });
|
|
47
|
+
return entity;
|
|
48
|
+
}, options);
|
|
49
|
+
entity.dispatchDomainEvents();
|
|
50
|
+
return entity;
|
|
51
|
+
}
|
|
52
|
+
async updateList(entities, options) {
|
|
53
|
+
await this.db.withTransaction(async (trx) => {
|
|
54
|
+
const dtos = await this.collectionMapper.fromEntitiesToDtos(entities);
|
|
55
|
+
await this.collectionDao.updateList(dtos, { ...options, trx });
|
|
56
|
+
}, options);
|
|
57
|
+
entities.forEach((entity) => entity.dispatchDomainEvents);
|
|
58
|
+
return entities;
|
|
59
|
+
}
|
|
60
|
+
async delete(entity, options) {
|
|
61
|
+
await this.withTransaction(async (trx) => {
|
|
62
|
+
await this.collectionDao.deleteById(entity.id, { ...options, trx });
|
|
63
|
+
return entity;
|
|
64
|
+
}, options);
|
|
65
|
+
entity.dispatchDomainEvents();
|
|
66
|
+
return entity;
|
|
67
|
+
}
|
|
68
|
+
async deleteList(entities, options) {
|
|
69
|
+
await this.db.withTransaction(async (trx) => {
|
|
70
|
+
entities.forEach((entity) => entity.dispatchDomainEvents());
|
|
71
|
+
await this.collectionDao.deleteList(entities.map((entity) => entity.id), { ...options, trx });
|
|
72
|
+
}, options);
|
|
73
|
+
return entities;
|
|
74
|
+
}
|
|
75
|
+
async find(input, options) {
|
|
76
|
+
const dtos = await this.collectionDao.find(input, options);
|
|
77
|
+
const entities = await this.collectionMapper.fromDtosToEntities(dtos);
|
|
78
|
+
return entities;
|
|
79
|
+
}
|
|
80
|
+
async findOne(input, options) {
|
|
81
|
+
const dto = await this.collectionDao.findOne(input, options);
|
|
82
|
+
const entity = dto ? await this.collectionMapper.fromDtoToEntity(dto) : dto;
|
|
83
|
+
return entity;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
CollectionRepository = __decorate([
|
|
87
|
+
(0, common_1.Repository)({ token: shared_1.COLLECTION_INJECT_TOKENS.REPOSITORY.COLLECTION, scope: common_1.Lifecycle.Singleton }),
|
|
88
|
+
__param(0, (0, common_1.DataSource)()),
|
|
89
|
+
__param(1, (0, common_1.Inject)(shared_1.COLLECTION_INJECT_TOKENS.DAO.COLLECTION)),
|
|
90
|
+
__param(2, (0, common_1.Inject)(shared_1.COLLECTION_INJECT_TOKENS.MAPPER.COLLECTION)),
|
|
91
|
+
__metadata("design:paramtypes", [Object, infra_1.CollectionDao, Object])
|
|
92
|
+
], CollectionRepository);
|
|
93
|
+
exports.CollectionRepository = CollectionRepository;
|
|
@@ -0,0 +1,19 @@
|
|
|
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("./collection.repository"), exports);
|
|
18
|
+
__exportStar(require("./product-collection.repository"), exports);
|
|
19
|
+
__exportStar(require("./post-collection.repository"), exports);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { BaseRepository, IDatabase, IRepository, QueryInput, QueryInputFindOne, RepositoryOptions } from '@cbidigital/aqua-ddd';
|
|
2
|
+
import { Optional } from '@heronjs/common';
|
|
3
|
+
import { IPostCollection } from '../entities';
|
|
4
|
+
import { PostCollectionDao } from '../../infra';
|
|
5
|
+
import { PostCollectionMapper } from '../mappers';
|
|
6
|
+
export interface IPostCollectionRepository extends IRepository<IPostCollection, RepositoryOptions> {
|
|
7
|
+
}
|
|
8
|
+
export declare class PostCollectionRepository extends BaseRepository<IPostCollection> implements IPostCollectionRepository {
|
|
9
|
+
protected readonly db: IDatabase;
|
|
10
|
+
protected readonly postCollectionDao: PostCollectionDao;
|
|
11
|
+
protected readonly postCollectionMapper: PostCollectionMapper;
|
|
12
|
+
constructor(db: IDatabase, postCollectionDao: PostCollectionDao, postCollectionMapper: PostCollectionMapper);
|
|
13
|
+
create(entity: IPostCollection, options?: RepositoryOptions): Promise<IPostCollection>;
|
|
14
|
+
update(entity: IPostCollection, options?: RepositoryOptions): Promise<IPostCollection>;
|
|
15
|
+
upsert(entity: IPostCollection, options?: RepositoryOptions): Promise<IPostCollection>;
|
|
16
|
+
upsertList(entities: IPostCollection[], options?: RepositoryOptions): Promise<IPostCollection[]>;
|
|
17
|
+
delete(entity: IPostCollection, options?: RepositoryOptions): Promise<IPostCollection>;
|
|
18
|
+
find(input: QueryInput, options?: RepositoryOptions): Promise<IPostCollection[]>;
|
|
19
|
+
findOne(input: QueryInputFindOne, options?: RepositoryOptions): Promise<Optional<IPostCollection>>;
|
|
20
|
+
deleteList(entities: IPostCollection[], options?: RepositoryOptions): Promise<IPostCollection[]>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
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.PostCollectionRepository = 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 mappers_1 = require("../mappers");
|
|
21
|
+
let PostCollectionRepository = class PostCollectionRepository extends aqua_ddd_1.BaseRepository {
|
|
22
|
+
constructor(db, postCollectionDao, postCollectionMapper) {
|
|
23
|
+
super({ db });
|
|
24
|
+
this.db = db;
|
|
25
|
+
this.postCollectionDao = postCollectionDao;
|
|
26
|
+
this.postCollectionMapper = postCollectionMapper;
|
|
27
|
+
}
|
|
28
|
+
async create(entity, options) {
|
|
29
|
+
await this.db.withTransaction(async (trx) => {
|
|
30
|
+
const dto = await this.postCollectionMapper.fromEntityToDto(entity);
|
|
31
|
+
await this.postCollectionDao.create(dto, { ...options, trx });
|
|
32
|
+
}, options);
|
|
33
|
+
entity.dispatchDomainEvents();
|
|
34
|
+
return entity;
|
|
35
|
+
}
|
|
36
|
+
async update(entity, options) {
|
|
37
|
+
await this.withTransaction(async (trx) => {
|
|
38
|
+
const dto = await this.postCollectionMapper.fromEntityToDto(entity);
|
|
39
|
+
await this.postCollectionDao.updateById(dto.id, dto, { ...options, trx });
|
|
40
|
+
return entity;
|
|
41
|
+
}, options);
|
|
42
|
+
entity.dispatchDomainEvents();
|
|
43
|
+
return entity;
|
|
44
|
+
}
|
|
45
|
+
async upsert(entity, options) {
|
|
46
|
+
try {
|
|
47
|
+
await this.withTransaction(async (trx) => {
|
|
48
|
+
const dto = await this.postCollectionMapper.fromEntityToDto(entity);
|
|
49
|
+
await this.postCollectionDao.upsert(dto, { ...options, trx });
|
|
50
|
+
return entity;
|
|
51
|
+
}, options);
|
|
52
|
+
entity.dispatchDomainEvents();
|
|
53
|
+
return entity;
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async upsertList(entities, options) {
|
|
60
|
+
try {
|
|
61
|
+
await this.withTransaction(async (trx) => {
|
|
62
|
+
const dto = await this.postCollectionMapper.fromEntitiesToDtos(entities);
|
|
63
|
+
await this.postCollectionDao.upsertList(dto, { ...options, trx });
|
|
64
|
+
return entities;
|
|
65
|
+
}, options);
|
|
66
|
+
entities.forEach((entity) => entity.dispatchDomainEvents());
|
|
67
|
+
return entities;
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
throw error;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
async delete(entity, options) {
|
|
74
|
+
await this.withTransaction(async (trx) => {
|
|
75
|
+
await this.postCollectionDao.deleteById(entity.id, { ...options, trx });
|
|
76
|
+
return entity;
|
|
77
|
+
}, options);
|
|
78
|
+
entity.dispatchDomainEvents();
|
|
79
|
+
return entity;
|
|
80
|
+
}
|
|
81
|
+
async find(input, options) {
|
|
82
|
+
const dtos = await this.postCollectionDao.find(input, options);
|
|
83
|
+
const entities = await this.postCollectionMapper.fromDtosToEntities(dtos);
|
|
84
|
+
return entities;
|
|
85
|
+
}
|
|
86
|
+
async findOne(input, options) {
|
|
87
|
+
const dto = await this.postCollectionDao.findOne(input, options);
|
|
88
|
+
const entity = dto ? await this.postCollectionMapper.fromDtoToEntity(dto) : dto;
|
|
89
|
+
return entity;
|
|
90
|
+
}
|
|
91
|
+
async deleteList(entities, options) {
|
|
92
|
+
await this.db.withTransaction(async (trx) => {
|
|
93
|
+
entities.forEach((entity) => entity.dispatchDomainEvents());
|
|
94
|
+
await this.postCollectionDao.deleteList(entities.map((entity) => entity.id), { ...options, trx });
|
|
95
|
+
}, options);
|
|
96
|
+
return entities;
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
PostCollectionRepository = __decorate([
|
|
100
|
+
(0, common_1.Repository)({ token: shared_1.COLLECTION_INJECT_TOKENS.REPOSITORY.POST_COLLECTION, scope: common_1.Lifecycle.Singleton }),
|
|
101
|
+
__param(0, (0, common_1.DataSource)()),
|
|
102
|
+
__param(1, (0, common_1.Inject)(shared_1.COLLECTION_INJECT_TOKENS.DAO.POST_COLLECTION)),
|
|
103
|
+
__param(2, (0, common_1.Inject)(shared_1.COLLECTION_INJECT_TOKENS.MAPPER.POST_COLLECTION)),
|
|
104
|
+
__metadata("design:paramtypes", [Object, infra_1.PostCollectionDao,
|
|
105
|
+
mappers_1.PostCollectionMapper])
|
|
106
|
+
], PostCollectionRepository);
|
|
107
|
+
exports.PostCollectionRepository = PostCollectionRepository;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { BaseRepository, IDatabase, IRepository, QueryInput, QueryInputFindOne, RepositoryOptions } from '@cbidigital/aqua-ddd';
|
|
2
|
+
import { Optional } from '@heronjs/common';
|
|
3
|
+
import { ProductCollectionDao } from '../../infra';
|
|
4
|
+
import { IProductCollection } from '../entities';
|
|
5
|
+
import { IProductCollectionMapper } from '../mappers';
|
|
6
|
+
export interface IProductCollectionRepository extends IRepository<IProductCollection, RepositoryOptions> {
|
|
7
|
+
}
|
|
8
|
+
export declare class ProductCollectionRepository extends BaseRepository<IProductCollection> implements IProductCollectionRepository {
|
|
9
|
+
protected readonly db: IDatabase;
|
|
10
|
+
protected readonly productCollectionDao: ProductCollectionDao;
|
|
11
|
+
protected readonly productCollectionMapper: IProductCollectionMapper;
|
|
12
|
+
constructor(db: IDatabase, productCollectionDao: ProductCollectionDao, productCollectionMapper: IProductCollectionMapper);
|
|
13
|
+
create(entity: IProductCollection, options?: RepositoryOptions): Promise<IProductCollection>;
|
|
14
|
+
createList(entities: IProductCollection[], options?: RepositoryOptions): Promise<IProductCollection[]>;
|
|
15
|
+
update(entity: IProductCollection, options?: RepositoryOptions): Promise<IProductCollection>;
|
|
16
|
+
updateList(entities: IProductCollection[], options?: RepositoryOptions): Promise<IProductCollection[]>;
|
|
17
|
+
delete(entity: IProductCollection, options?: RepositoryOptions): Promise<IProductCollection>;
|
|
18
|
+
deleteList(entities: IProductCollection[], options?: RepositoryOptions): Promise<IProductCollection[]>;
|
|
19
|
+
find(input: QueryInput, options?: RepositoryOptions): Promise<IProductCollection[]>;
|
|
20
|
+
findOne(input: QueryInputFindOne, options?: RepositoryOptions): Promise<Optional<IProductCollection>>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
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.ProductCollectionRepository = 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
|
+
let ProductCollectionRepository = class ProductCollectionRepository extends aqua_ddd_1.BaseRepository {
|
|
21
|
+
constructor(db, productCollectionDao, productCollectionMapper) {
|
|
22
|
+
super({ db });
|
|
23
|
+
this.db = db;
|
|
24
|
+
this.productCollectionDao = productCollectionDao;
|
|
25
|
+
this.productCollectionMapper = productCollectionMapper;
|
|
26
|
+
}
|
|
27
|
+
async create(entity, options) {
|
|
28
|
+
await this.db.withTransaction(async (trx) => {
|
|
29
|
+
const dto = await this.productCollectionMapper.fromEntityToDto(entity);
|
|
30
|
+
await this.productCollectionDao.create(dto, { ...options, trx });
|
|
31
|
+
}, options);
|
|
32
|
+
entity.dispatchDomainEvents();
|
|
33
|
+
return entity;
|
|
34
|
+
}
|
|
35
|
+
async createList(entities, options) {
|
|
36
|
+
await this.db.withTransaction(async (trx) => {
|
|
37
|
+
const dtos = await this.productCollectionMapper.fromEntitiesToDtos(entities);
|
|
38
|
+
await this.productCollectionDao.createList(dtos, { ...options, trx });
|
|
39
|
+
}, options);
|
|
40
|
+
entities.forEach((entity) => entity.dispatchDomainEvents());
|
|
41
|
+
return entities;
|
|
42
|
+
}
|
|
43
|
+
async update(entity, options) {
|
|
44
|
+
await this.withTransaction(async (trx) => {
|
|
45
|
+
const dto = await this.productCollectionMapper.fromEntityToDto(entity);
|
|
46
|
+
await this.productCollectionDao.updateById(dto.id, dto, { ...options, trx });
|
|
47
|
+
return entity;
|
|
48
|
+
}, options);
|
|
49
|
+
entity.dispatchDomainEvents();
|
|
50
|
+
return entity;
|
|
51
|
+
}
|
|
52
|
+
async updateList(entities, options) {
|
|
53
|
+
await this.db.withTransaction(async (trx) => {
|
|
54
|
+
const dtos = await this.productCollectionMapper.fromEntitiesToDtos(entities);
|
|
55
|
+
await this.productCollectionDao.updateList(dtos, { ...options, trx });
|
|
56
|
+
}, options);
|
|
57
|
+
entities.forEach((entity) => entity.dispatchDomainEvents);
|
|
58
|
+
return entities;
|
|
59
|
+
}
|
|
60
|
+
async delete(entity, options) {
|
|
61
|
+
await this.withTransaction(async (trx) => {
|
|
62
|
+
await this.productCollectionDao.deleteById(entity.id, { ...options, trx });
|
|
63
|
+
return entity;
|
|
64
|
+
}, options);
|
|
65
|
+
entity.dispatchDomainEvents();
|
|
66
|
+
return entity;
|
|
67
|
+
}
|
|
68
|
+
async deleteList(entities, options) {
|
|
69
|
+
await this.db.withTransaction(async (trx) => {
|
|
70
|
+
entities.forEach((entity) => entity.dispatchDomainEvents());
|
|
71
|
+
await this.productCollectionDao.deleteList(entities.map((entity) => entity.id), { ...options, trx });
|
|
72
|
+
}, options);
|
|
73
|
+
return entities;
|
|
74
|
+
}
|
|
75
|
+
async find(input, options) {
|
|
76
|
+
const dtos = await this.productCollectionDao.find(input, options);
|
|
77
|
+
const entities = await this.productCollectionMapper.fromDtosToEntities(dtos);
|
|
78
|
+
return entities;
|
|
79
|
+
}
|
|
80
|
+
async findOne(input, options) {
|
|
81
|
+
const dto = await this.productCollectionDao.findOne(input, options);
|
|
82
|
+
const entity = dto
|
|
83
|
+
? await this.productCollectionMapper.fromDtoToEntity(dto)
|
|
84
|
+
: dto;
|
|
85
|
+
return entity;
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
ProductCollectionRepository = __decorate([
|
|
89
|
+
(0, common_1.Repository)({
|
|
90
|
+
token: shared_1.COLLECTION_INJECT_TOKENS.REPOSITORY.PRODUCT_COLLECTION,
|
|
91
|
+
scope: common_1.Lifecycle.Singleton,
|
|
92
|
+
}),
|
|
93
|
+
__param(0, (0, common_1.DataSource)()),
|
|
94
|
+
__param(1, (0, common_1.Inject)(shared_1.COLLECTION_INJECT_TOKENS.DAO.PRODUCT_COLLECTION)),
|
|
95
|
+
__param(2, (0, common_1.Inject)(shared_1.COLLECTION_INJECT_TOKENS.MAPPER.PRODUCT_COLLECTION)),
|
|
96
|
+
__metadata("design:paramtypes", [Object, infra_1.ProductCollectionDao, Object])
|
|
97
|
+
], ProductCollectionRepository);
|
|
98
|
+
exports.ProductCollectionRepository = ProductCollectionRepository;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
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("./presentation"), exports);
|
|
18
|
+
__exportStar(require("./collection.module"), exports);
|
|
19
|
+
__exportStar(require("./infra"), exports);
|
|
20
|
+
__exportStar(require("./domain"), exports);
|
|
21
|
+
__exportStar(require("./app"), exports);
|
|
22
|
+
// Note: shared folder is not exported at the top level to avoid conflicts
|
|
23
|
+
// When using the module as npm package, import from './shared' directly if needed
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { BaseDao, IBaseDao, IDatabase } from '@cbidigital/aqua-ddd';
|
|
2
|
+
import { CollectionDto } from '../../domain';
|
|
3
|
+
import { CollectionRecord } from '../records';
|
|
4
|
+
export type ICollectionDao = IBaseDao<CollectionDto, CollectionRecord>;
|
|
5
|
+
export declare class CollectionDao extends BaseDao<CollectionDto, CollectionRecord> implements ICollectionDao {
|
|
6
|
+
constructor(db: IDatabase);
|
|
7
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
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.CollectionDao = void 0;
|
|
16
|
+
const common_1 = require("@heronjs/common");
|
|
17
|
+
const shared_1 = require("../../shared");
|
|
18
|
+
const aqua_ddd_1 = require("@cbidigital/aqua-ddd");
|
|
19
|
+
const mappers_1 = require("../mappers");
|
|
20
|
+
const query_configs_1 = require("../query-configs");
|
|
21
|
+
let CollectionDao = class CollectionDao extends aqua_ddd_1.BaseDao {
|
|
22
|
+
constructor(db) {
|
|
23
|
+
super({
|
|
24
|
+
db,
|
|
25
|
+
tableName: shared_1.COLLECTION_TABLE_NAMES.COLLECTION,
|
|
26
|
+
recordMapper: new mappers_1.CollectionRecordMapper(),
|
|
27
|
+
queryConfig: query_configs_1.CollectionQueryConfig,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
CollectionDao = __decorate([
|
|
32
|
+
(0, common_1.Dao)({ token: shared_1.COLLECTION_INJECT_TOKENS.DAO.COLLECTION, scope: common_1.Lifecycle.Singleton }),
|
|
33
|
+
__param(0, (0, common_1.DataSource)()),
|
|
34
|
+
__metadata("design:paramtypes", [Object])
|
|
35
|
+
], CollectionDao);
|
|
36
|
+
exports.CollectionDao = CollectionDao;
|
|
@@ -0,0 +1,19 @@
|
|
|
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("./collection.dao"), exports);
|
|
18
|
+
__exportStar(require("./product-collection.dao"), exports);
|
|
19
|
+
__exportStar(require("./post-collection.dao"), exports);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BaseDao, IBaseDao, IDatabase, RepositoryOptions } from '@cbidigital/aqua-ddd';
|
|
2
|
+
import { PostCollectionDto } from '../../domain';
|
|
3
|
+
import { PostCollectionRecord } from '../records';
|
|
4
|
+
export type IPostCollectionDao = IBaseDao<PostCollectionDto, PostCollectionRecord>;
|
|
5
|
+
export declare class PostCollectionDao extends BaseDao<PostCollectionDto, PostCollectionRecord> implements IPostCollectionDao {
|
|
6
|
+
private readonly postCollectionRecordMapper;
|
|
7
|
+
constructor(db: IDatabase);
|
|
8
|
+
upsert(dto: Partial<PostCollectionDto>, options?: RepositoryOptions): Promise<Partial<PostCollectionDto>>;
|
|
9
|
+
findPostsLinkedProduct(collectionId: string, options?: RepositoryOptions): Promise<PostCollectionDto[]>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
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.PostCollectionDao = void 0;
|
|
16
|
+
const common_1 = require("@heronjs/common");
|
|
17
|
+
const shared_1 = require("../../shared");
|
|
18
|
+
const aqua_ddd_1 = require("@cbidigital/aqua-ddd");
|
|
19
|
+
const mappers_1 = require("../mappers");
|
|
20
|
+
const query_configs_1 = require("../query-configs");
|
|
21
|
+
let PostCollectionDao = class PostCollectionDao extends aqua_ddd_1.BaseDao {
|
|
22
|
+
constructor(db) {
|
|
23
|
+
super({
|
|
24
|
+
db,
|
|
25
|
+
tableName: shared_1.COLLECTION_TABLE_NAMES.POST_COLLECTION,
|
|
26
|
+
recordMapper: new mappers_1.PostCollectionRecordMapper(),
|
|
27
|
+
queryConfig: query_configs_1.PostCollectionQueryConfig,
|
|
28
|
+
});
|
|
29
|
+
this.postCollectionRecordMapper = new mappers_1.PostCollectionRecordMapper();
|
|
30
|
+
}
|
|
31
|
+
async upsert(dto, options = {}) {
|
|
32
|
+
return this.db.withTransaction(async (trx, client) => {
|
|
33
|
+
const record = this.postCollectionRecordMapper.fromDtoToRecord(dto);
|
|
34
|
+
const query = client
|
|
35
|
+
.from(this.tableName)
|
|
36
|
+
.insert(record)
|
|
37
|
+
.onConflict(['ambassador_id', 'collection_id', 'post_id'])
|
|
38
|
+
.merge();
|
|
39
|
+
if (trx)
|
|
40
|
+
query.transacting(trx);
|
|
41
|
+
await query;
|
|
42
|
+
return dto;
|
|
43
|
+
}, options);
|
|
44
|
+
}
|
|
45
|
+
async findPostsLinkedProduct(collectionId, options = {}) {
|
|
46
|
+
const tenantId = options?.tenantId;
|
|
47
|
+
const client = this.db.getClient(tenantId);
|
|
48
|
+
const query = client
|
|
49
|
+
.select([
|
|
50
|
+
`${shared_1.COLLECTION_TABLE_NAMES_ALIAS.POST_COLLECTION}.post_id`,
|
|
51
|
+
`${shared_1.COLLECTION_TABLE_NAMES_ALIAS.POST_COLLECTION}.hidden`,
|
|
52
|
+
])
|
|
53
|
+
.from({ [shared_1.COLLECTION_TABLE_NAMES_ALIAS.POST_COLLECTION]: this.tableName })
|
|
54
|
+
.join({ [shared_1.COLLECTION_TABLE_NAMES_ALIAS.POST_PRODUCT]: shared_1.COLLECTION_TABLE_NAMES.POST_PRODUCT }, `${[shared_1.COLLECTION_TABLE_NAMES_ALIAS.POST_COLLECTION]}.post_id`, `${[shared_1.COLLECTION_TABLE_NAMES_ALIAS.POST_PRODUCT]}.post_id`)
|
|
55
|
+
.where(`${shared_1.COLLECTION_TABLE_NAMES_ALIAS.POST_COLLECTION}.collection_id`, collectionId)
|
|
56
|
+
.groupBy([
|
|
57
|
+
`${shared_1.COLLECTION_TABLE_NAMES_ALIAS.POST_COLLECTION}.post_id`,
|
|
58
|
+
`${shared_1.COLLECTION_TABLE_NAMES_ALIAS.POST_COLLECTION}.hidden`,
|
|
59
|
+
]);
|
|
60
|
+
const records = await query;
|
|
61
|
+
const dtos = this.postCollectionRecordMapper.fromRecordsToDtos(records);
|
|
62
|
+
return dtos;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
PostCollectionDao = __decorate([
|
|
66
|
+
(0, common_1.Dao)({ token: shared_1.COLLECTION_INJECT_TOKENS.DAO.POST_COLLECTION, scope: common_1.Lifecycle.Singleton }),
|
|
67
|
+
__param(0, (0, common_1.DataSource)()),
|
|
68
|
+
__metadata("design:paramtypes", [Object])
|
|
69
|
+
], PostCollectionDao);
|
|
70
|
+
exports.PostCollectionDao = PostCollectionDao;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BaseDao, IBaseDao, IDatabase, QueryInput, RepositoryOptions } from '@cbidigital/aqua-ddd';
|
|
2
|
+
import { ProductCollectionDto } from '../../domain';
|
|
3
|
+
import { ProductCollectionRecord } from '../records';
|
|
4
|
+
export type IProductCollectionDao = IBaseDao<ProductCollectionDto, ProductCollectionRecord>;
|
|
5
|
+
export declare class ProductCollectionDao extends BaseDao<ProductCollectionDto, ProductCollectionRecord> implements IProductCollectionDao {
|
|
6
|
+
constructor(db: IDatabase);
|
|
7
|
+
find(payload?: QueryInput<ProductCollectionDto>, options?: RepositoryOptions): Promise<ProductCollectionDto[]>;
|
|
8
|
+
count(payload?: QueryInput<ProductCollectionDto>, options?: RepositoryOptions): Promise<number>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
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.ProductCollectionDao = void 0;
|
|
16
|
+
const common_1 = require("@heronjs/common");
|
|
17
|
+
const shared_1 = require("../../shared");
|
|
18
|
+
const aqua_ddd_1 = require("@cbidigital/aqua-ddd");
|
|
19
|
+
const mappers_1 = require("../mappers");
|
|
20
|
+
const query_configs_1 = require("../query-configs");
|
|
21
|
+
let ProductCollectionDao = class ProductCollectionDao extends aqua_ddd_1.BaseDao {
|
|
22
|
+
constructor(db) {
|
|
23
|
+
super({
|
|
24
|
+
db,
|
|
25
|
+
tableName: shared_1.COLLECTION_TABLE_NAMES.PRODUCT_COLLECTION,
|
|
26
|
+
recordMapper: new mappers_1.ProductCollectionRecordMapper(),
|
|
27
|
+
queryConfig: query_configs_1.ProductCollectionQueryConfig,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
async find(payload, options) {
|
|
31
|
+
const { sort } = payload ?? {};
|
|
32
|
+
const tenantId = options?.tenantId;
|
|
33
|
+
const client = this.db.getClient(tenantId);
|
|
34
|
+
const query = client
|
|
35
|
+
.select([
|
|
36
|
+
`${shared_1.COLLECTION_TABLE_NAMES_ALIAS.PRODUCT_COLLECTION}.* `,
|
|
37
|
+
`${shared_1.COLLECTION_TABLE_NAMES_ALIAS.COLLECTION}.collection_name `,
|
|
38
|
+
])
|
|
39
|
+
.from({ [shared_1.COLLECTION_TABLE_NAMES_ALIAS.PRODUCT_COLLECTION]: this.tableName })
|
|
40
|
+
.leftJoin({ [shared_1.COLLECTION_TABLE_NAMES_ALIAS.COLLECTION]: shared_1.COLLECTION_TABLE_NAMES.COLLECTION }, `${[shared_1.COLLECTION_TABLE_NAMES_ALIAS.PRODUCT_COLLECTION]}.collection_id`, `${[shared_1.COLLECTION_TABLE_NAMES_ALIAS.COLLECTION]}.id`)
|
|
41
|
+
.groupBy([
|
|
42
|
+
`${shared_1.COLLECTION_TABLE_NAMES_ALIAS.PRODUCT_COLLECTION}.id`,
|
|
43
|
+
`${shared_1.COLLECTION_TABLE_NAMES_ALIAS.COLLECTION}.collection_name`,
|
|
44
|
+
]);
|
|
45
|
+
if (payload?.filter !== undefined)
|
|
46
|
+
aqua_ddd_1.DaoUtils.applyFilter(payload.filter, this.queryConfig, query);
|
|
47
|
+
const records = await query;
|
|
48
|
+
const dtos = this.recordMapper.fromRecordsToDtos(records);
|
|
49
|
+
return dtos;
|
|
50
|
+
}
|
|
51
|
+
async count(payload, options) {
|
|
52
|
+
const tenantId = options?.tenantId;
|
|
53
|
+
const client = this.db.getClient(tenantId);
|
|
54
|
+
const query = client
|
|
55
|
+
.select(client.raw(`count(distinct ${shared_1.COLLECTION_TABLE_NAMES_ALIAS.PRODUCT_COLLECTION}.id) as total_count`))
|
|
56
|
+
.from({ [shared_1.COLLECTION_TABLE_NAMES_ALIAS.PRODUCT_COLLECTION]: this.tableName })
|
|
57
|
+
.first();
|
|
58
|
+
if (payload?.filter !== undefined)
|
|
59
|
+
aqua_ddd_1.DaoUtils.applyFilter(payload.filter, this.queryConfig, query);
|
|
60
|
+
const record = await query;
|
|
61
|
+
return Number(record?.total_count);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
ProductCollectionDao = __decorate([
|
|
65
|
+
(0, common_1.Dao)({ token: shared_1.COLLECTION_INJECT_TOKENS.DAO.PRODUCT_COLLECTION, scope: common_1.Lifecycle.Singleton }),
|
|
66
|
+
__param(0, (0, common_1.DataSource)()),
|
|
67
|
+
__metadata("design:paramtypes", [Object])
|
|
68
|
+
], ProductCollectionDao);
|
|
69
|
+
exports.ProductCollectionDao = ProductCollectionDao;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { DomainEvent, IAggregateRoot, IDomainEventEmitter } from '@cbidigital/aqua-ddd';
|
|
2
|
+
export declare class CollectionDomainEventEmitter<T extends IAggregateRoot> implements IDomainEventEmitter<T> {
|
|
3
|
+
private readonly logger;
|
|
4
|
+
constructor();
|
|
5
|
+
emit(name: string, data?: DomainEvent<T>): void;
|
|
6
|
+
}
|