UNPKG

@tomei/finance

Version:

NestJS package for finance module

112 lines 4.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Tag = void 0; const general_1 = require("@tomei/general"); const tag_repository_1 = require("./tag.repository"); class Tag extends general_1.ObjectBase { get TagId() { return this.ObjectId; } set TagId(value) { this.ObjectId = value; } constructor(tagGroupAttr) { super(); this.AccSystemRefId = null; this.PostedToAccSystemYN = 'N'; this.ObjectId = 'New'; this.ObjectType = 'Tag'; this.TableName = 'finance_Tag'; if (tagGroupAttr) { this.TagId = tagGroupAttr.TagId; this.TagGroupId = tagGroupAttr.TagGroupId; this.TagName = tagGroupAttr.TagName; this.CreatedById = tagGroupAttr.CreatedById; this.CreatedAt = tagGroupAttr.CreatedAt; this.UpdatedById = tagGroupAttr.UpdatedById; this.UpdatedAt = tagGroupAttr.UpdatedAt; this.AccSystemRefId = tagGroupAttr.AccSystemRefId; this.PostedToAccSystemYN = tagGroupAttr.PostedToAccSystemYN; this.PostedById = tagGroupAttr.PostedById; this.PostedDateTime = tagGroupAttr.PostedDateTime; } } static async init(dbTransaction, repository, tagId) { try { let instance; if (!dbTransaction || !repository) { throw new Error('Repository and dbTransaction are required for initialization.'); } if (tagId) { const data = await repository.findByPk(tagId); if (!data) { throw new general_1.ClassError('Tag', 'TagErrMsg01', 'Tag not found.', 'init', 404); } instance = new Tag(data); } else { instance = new Tag(); } instance.initializeRepository(repository); return instance; } catch (error) { throw new general_1.ClassError('TagGroup', 'TagErrMsg02', 'Failed to initialize tag instance.', 'init', 500); } } async create(loginUser, dbTransaction) { try { this.TagId = this.createId(); this.CreatedAt = new Date(); this.UpdatedAt = new Date(); this.CreatedById = loginUser.ObjectId; this.UpdatedById = loginUser.ObjectId; const payload = { TagId: this.TagId, TagGroupId: this.TagGroupId, TagName: this.TagName, CreatedById: this.CreatedById, CreatedAt: this.CreatedAt, UpdatedById: this.UpdatedById, UpdatedAt: this.UpdatedAt, AccSystemRefId: this.AccSystemRefId, PostedToAccSystemYN: this.PostedToAccSystemYN, PostedById: this.PostedById, PostedDateTime: this.PostedDateTime, }; const data = await this._repository.create(payload, { transaction: dbTransaction, }); return this; } catch (error) { throw error; } } static async findTag(tagName, tagGroupId, dbTransaction) { try { const tagRepository = new tag_repository_1.TagRepository(); let payload = { TagName: tagName, }; if (tagGroupId) { payload.TagGroupId = tagGroupId; } const data = await tagRepository.findOne({ where: payload, transaction: dbTransaction, }); if (!data) { return null; } const tag = new Tag(data); tag._repository = tagRepository; return tag; } catch (error) { throw new general_1.ClassError('Tag', 'TagErrMsg02', 'Failed to find tag.', 'findTag', 500); } } } exports.Tag = Tag; //# sourceMappingURL=tag.js.map