@tomei/finance
Version:
NestJS package for finance module
108 lines • 4.32 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TagGroup = void 0;
const general_1 = require("@tomei/general");
const tag_group_repository_1 = require("./tag-group.repository");
const dist_1 = require("@tomei/activity-history/dist");
class TagGroup extends general_1.ObjectBase {
get TagGroupId() {
return this.ObjectId;
}
set TagGroupId(value) {
this.ObjectId = value;
}
constructor(tagGroupAttr) {
super();
this.PostedToAccSystemYN = 'N';
this.ObjectId = 'New';
this.ObjectType = 'TagGroup';
this.TableName = 'finance_TagGroup';
if (tagGroupAttr) {
this.TagGroupId = tagGroupAttr.TagGroupId;
this.TagGroupName = tagGroupAttr.TagGroupName;
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, tagGroupId) {
try {
let instance;
if (!dbTransaction || !repository) {
throw new Error('Repository and dbTransaction are required for initialization.');
}
if (tagGroupId) {
const data = await repository.findByPk(tagGroupId);
if (!data) {
throw new general_1.ClassError('TagGroup', 'TagGroupErrMsg01', 'Tag Group not found.', 'init', 404);
}
instance = new TagGroup(data);
}
else {
instance = new TagGroup();
}
instance.initializeRepository(repository);
return instance;
}
catch (error) {
throw new general_1.ClassError('TagGroup', 'TagGroupErrMsg01', 'Failed to initialize tag group instance.', 'init', 500);
}
}
async create(loginUser, dbTransaction) {
try {
this.TagGroupId = this.createId();
this.CreatedById = loginUser.ObjectId;
this.CreatedAt = new Date();
this.UpdatedById = loginUser.ObjectId;
this.UpdatedAt = new Date();
const payload = {
TagGroupId: this.createId(),
TagGroupName: this.TagGroupName,
CreatedById: this.CreatedById,
CreatedAt: new Date(),
UpdatedById: this.UpdatedById,
UpdatedAt: new Date(),
AccSystemRefId: this.AccSystemRefId,
PostedToAccSystemYN: this.PostedToAccSystemYN,
PostedById: this.PostedById,
PostedDateTime: this.PostedDateTime,
};
const data = await this._repository.create(payload, {
transaction: dbTransaction,
});
const activity = new dist_1.Activity();
activity.ActivityId = this._createId().toUpperCase();
activity.Action = dist_1.ActionEnum.CREATE;
activity.Description = `Create new tag group: ${this.TagGroupName}`;
activity.EntityId = this.TagGroupId;
activity.EntityType = this.ObjectType;
activity.EntityValueBefore = JSON.stringify({});
activity.EntityValueAfter = JSON.stringify(payload);
await activity.create(loginUser.ObjectId, dbTransaction);
return new TagGroup(data);
}
catch (error) {
throw error;
}
}
static async findByName(tagGroupName, dbTransaction) {
try {
const repo = new tag_group_repository_1.TagGroupRepository();
const data = await repo.findOne({
where: { TagGroupName: tagGroupName },
transaction: dbTransaction,
});
return data ? new TagGroup(data) : null;
}
catch (error) {
throw error;
}
}
}
exports.TagGroup = TagGroup;
//# sourceMappingURL=tag-group.js.map