UNPKG

@tomei/live-price

Version:

Tomei live-price Package

165 lines 7.31 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.FeedCutOffHistory = void 0; const general_1 = require("@tomei/general"); const feed_enum_1 = require("../../enum/feed.enum"); const feed_cut_off_history_repository_1 = require("./feed-cut-off-history.repository"); const sequelize_1 = require("sequelize"); class FeedCutOffHistory extends general_1.ObjectBase { get FeedCutOffHistoryId() { return this.ObjectId; } set FeedCutOffHistoryId(value) { this.ObjectId = value; } constructor(feedCutOffHistory) { super(); this.ObjectType = FeedCutOffHistory.name; if (feedCutOffHistory) { this.ObjectId = feedCutOffHistory.FeedCutOffHistoryId; this.FeedName = feedCutOffHistory.FeedName; this.Status = feedCutOffHistory.Status; this.ActivationDateTime = feedCutOffHistory.ActivationDateTime; this.ActivationTrigger = feedCutOffHistory.ActivationTrigger; this.ActivatedById = feedCutOffHistory.ActivatedById; this.DeactivationDateTime = feedCutOffHistory.DeactivationDateTime; this.DeactivatedById = feedCutOffHistory.DeactivatedById; } } static init(feedCutOffHistoryId, dbTransaction) { return __awaiter(this, void 0, void 0, function* () { try { if (feedCutOffHistoryId) { const data = yield this._Repo.findByPk(feedCutOffHistoryId, { transaction: dbTransaction, }); if (data) { return new FeedCutOffHistory(data); } else { throw new general_1.ClassError('FeedCutOffHistory', 'FeedCutOffHistoryErrMsg01', 'FeedCutOffHistory not found', 'init'); } } return new FeedCutOffHistory(); } catch (error) { throw error; } }); } create(dbTransaction, activatedById) { return __awaiter(this, void 0, void 0, function* () { try { if (!this.FeedName || !this.ActivationTrigger) { throw new general_1.ClassError('FeedCutOffHistory', 'FeedCutOffHistoryErrMsg02', 'Missing required fields', 'create'); } this.ObjectId = this.createId(); this.Status = feed_enum_1.CutOffStatus.ACTIVE; this.ActivationDateTime = new Date(); if (activatedById) { this.ActivatedById = activatedById; } yield FeedCutOffHistory._Repo.create({ FeedCutOffHistoryId: this.ObjectId, FeedName: this.FeedName, Status: this.Status, ActivationDateTime: this.ActivationDateTime, ActivationTrigger: this.ActivationTrigger, ActivatedById: this.ActivatedById, DeactivationDateTime: this.DeactivationDateTime, DeactivatedById: this.DeactivatedById, }, { transaction: dbTransaction, }); return this; } catch (error) { throw error; } }); } static deactivate(feedName, deactivatedById, dbTransaction) { return __awaiter(this, void 0, void 0, function* () { try { const data = yield FeedCutOffHistory._Repo.findAll({ order: [['ActivationDateTime', 'DESC']], transaction: dbTransaction, where: { FeedName: feedName, Status: feed_enum_1.CutOffStatus.ACTIVE, }, }); if (!data) { throw new general_1.ClassError('FeedCutOffHistory', 'FeedCutOffHistoryErrMsg03', 'FeedCutOffHistory not found', 'deactivate'); } for (const item of data) { item.DeactivationDateTime = new Date(); item.DeactivatedById = deactivatedById; item.Status = feed_enum_1.CutOffStatus.DEACTIVATED; yield item.save({ transaction: dbTransaction, }); } return new FeedCutOffHistory(data[0]); } catch (error) { throw error; } }); } static findAll(page, row, search, dbTransaction) { return __awaiter(this, void 0, void 0, function* () { try { const queryObj = {}; const options = { transaction: dbTransaction, limit: row, offset: row * (page - 1), order: [['ActivationDateTime', 'DESC']], }; if (search) { if (search.ActivationDateTime) { queryObj.ActivationDateTime = { [sequelize_1.Op.between]: [ search.ActivationDateTime.startDate, search.ActivationDateTime.endDate, ], }; } if (search.DeactivationDateTime) { queryObj.DeactivationDateTime = { [sequelize_1.Op.between]: [ search.DeactivationDateTime.startDate, search.DeactivationDateTime.endDate, ], }; } if (search.ActivationTrigger) { queryObj.ActivationTrigger = search.ActivationTrigger; } if (search.FeedName) { queryObj.FeedName = { [sequelize_1.Op.like]: `%${search.FeedName}%`, }; } } return yield FeedCutOffHistory._Repo.findAllWithPagination(Object.assign({ where: queryObj }, options)); } catch (error) { throw error; } }); } } exports.FeedCutOffHistory = FeedCutOffHistory; FeedCutOffHistory._Repo = new feed_cut_off_history_repository_1.FeedCutOffHistoryRepository(); //# sourceMappingURL=feed-cut-off-history.js.map