@comasoft/nestjs 0.1.48 → 0.1.49
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=this&&this.__decorate||function(e,t,r,n){var o
|
|
1
|
+
var e=this&&this.__decorate||function(e,t,r,n){var i,o=arguments.length,d=o<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)d=Reflect.decorate(e,t,r,n);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(d=(o<3?i(d):o>3?i(t,r,d):i(t,r))||d);return o>3&&d&&Object.defineProperty(t,r,d),d},t=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},r=this&&this.__param||function(e,t){return function(r,n){t(r,n,e)}},n=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))(function(i,o){function fulfilled(e){try{step(n.next(e))}catch(e){o(e)}}function rejected(e){try{step(n.throw(e))}catch(e){o(e)}}function step(e){e.done?i(e.value):function adopt(e){return e instanceof r?e:new r(function(t){t(e)})}(e.value).then(fulfilled,rejected)}step((n=n.apply(e,t||[])).next())})};Object.defineProperty(exports,"__esModule",{value:!0}),exports.CommentService=void 0;const i=require("@nestjs/common"),o=require("@nestjs/typeorm"),d=require("class-transformer"),s=require("typeorm"),a=require("../database/entities"),c=require("../utils"),u=require("./dto");let m=class CommentService{constructor(e,t){this.repository=e,this.dataSource=t}resolveTargetId(e,t,r){return n(this,void 0,void 0,function*(){if(t)return t;if(!r)throw new i.BadRequestException("Either target_id or target_uid is required");throw new i.BadRequestException("resolveTargetId must be implemented in app service")})}updateTargetCommentCount(e,t,r,o){return n(this,void 0,void 0,function*(){throw new i.BadRequestException("updateTargetCommentCount must be implemented in app service")})}calculateTreeStructure(e,t,r){return n(this,void 0,void 0,function*(){if(r){const n=yield this.repository.findOne({where:{id:r,target:e,target_id:t,deleted_at:null}});if(!n)throw new i.NotFoundException("Parent comment not found");const o=yield this.repository.createQueryBuilder("comments").select("MAX(comments.sort)","maxSort").where("comments.target = :target",{target:e}).andWhere("comments.target_id = :target_id",{target_id:t}).andWhere("comments.group_id = :group_id",{group_id:n.group_id}).andWhere("comments.deleted_at IS NULL").getRawOne();return{group_id:n.group_id,depth:n.depth+1,sort:((null==o?void 0:o.maxSort)||0)+1}}{const r=yield this.repository.createQueryBuilder("comments").select("MAX(comments.sort)","maxSort").where("comments.target = :target",{target:e}).andWhere("comments.target_id = :target_id",{target_id:t}).andWhere("comments.parent_id IS NULL").andWhere("comments.deleted_at IS NULL").getRawOne();return{group_id:0,depth:0,sort:((null==r?void 0:r.maxSort)||0)+1}}})}create(e,t){return n(this,void 0,void 0,function*(){const{target:r,target_id:i,target_uid:o,parent_id:s,content:c}=t,m=yield this.resolveTargetId(r,i,o),l=yield this.calculateTreeStructure(r,m,s),p=yield this.dataSource.transaction(t=>n(this,void 0,void 0,function*(){const n=yield t.save(a.Comment,Object.assign(Object.assign({target:r,target_id:m,parent_id:s},l),{user_id:e,content:c}));return s||(yield t.update(a.Comment,n.id,{group_id:n.id})),s&&(yield t.increment(a.Comment,{id:s},"cnt_replies",1)),yield this.updateTargetCommentCount(t,r,m,1),yield t.findOne(a.Comment,{where:{id:n.id}})}));return(0,d.plainToClass)(u.ResponseCommentBaseDto,p)})}paginateRaw(e,t,r){return n(this,void 0,void 0,function*(){const{page:n,limit:i}=t,[o,d]=yield Promise.all([e.skip((n-1)*i).take(i).getRawMany(),e.getCount()]),s=Math.ceil(d/i);return{items:o.map(r),pagination:{page:n,limit:i,count:o.length,count_total:d,count_page:s}}})}findAll(e,t,r,i){return n(this,void 0,void 0,function*(){const{_page:n,_limit:o,_keyword:s,_group:a,_sort:m}=e;let l=this.repository.createQueryBuilder("comments").leftJoin("users","user","comments.user_id = user.id").addSelect(["user.id","user.uid","user.name","user.profile_image","user.info_department","user.info_position"]).where("comments.deleted_at IS NULL");if(t&&l.andWhere("comments.target = :target",{target:t}),r||i){const e=t?yield this.resolveTargetId(t,r,i):r;l.andWhere("comments.target_id = :target_id",{target_id:e})}l=(0,c.applyFiltersAndSorting)(l,{_keyword:s,_group:a,_sort:m,keywordFields:["content"],aliasName:"comments"}),m||l.orderBy("comments.group_id","ASC").addOrderBy("comments.sort","ASC");const p=yield this.paginateRaw(l,{page:n,limit:o},e=>({id:e.comments_id,target:e.comments_target,target_id:e.comments_target_id,parent_id:e.comments_parent_id,group_id:e.comments_group_id,depth:e.comments_depth,sort:e.comments_sort,content:e.comments_content,cnt_likes:e.comments_cnt_likes,cnt_replies:e.comments_cnt_replies,created_at:e.comments_created_at,updated_at:e.comments_updated_at,user:{id:e.user_id,uid:e.user_uid,name:e.user_name,profile_image:e.user_profile_image,info_department:e.user_info_department,info_position:e.user_info_position}}));return(0,d.plainToClass)(u.ResponseCommentsBaseDto,p)})}update(e,t,r){return n(this,void 0,void 0,function*(){const n=yield this.repository.findOne({where:{id:t,deleted_at:null}});if(!n)throw new i.NotFoundException(`Comment with ID ${t} not found`);if(n.user_id!==e)throw new i.BadRequestException("You can only update your own comments");yield this.repository.update(t,r)})}remove(e,t){return n(this,void 0,void 0,function*(){const r=yield this.repository.findOne({where:{id:t,deleted_at:null}});if(!r)throw new i.NotFoundException(`Comment with ID ${t} not found`);if(r.user_id!==e)throw new i.BadRequestException("You can only delete your own comments");yield this.dataSource.transaction(e=>n(this,void 0,void 0,function*(){yield e.softDelete(a.Comment,t),yield e.update(a.Comment,t,{content:""}),r.parent_id&&(yield e.decrement(a.Comment,{id:r.parent_id},"cnt_replies",1)),yield this.updateTargetCommentCount(e,r.target,r.target_id,-1)}))})}};exports.CommentService=m,exports.CommentService=m=e([(0,i.Injectable)(),r(0,(0,o.InjectRepository)(a.Comment)),t("design:paramtypes",[s.Repository,s.DataSource])],m);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=this&&this.__decorate||function(e,o,t,s){var p,n=arguments.length,r=n<3?o:null===s?s=Object.getOwnPropertyDescriptor(o,t):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,o,t,s);else for(var i=e.length-1;i>=0;i--)(p=e[i])&&(r=(n<3?p(r):n>3?p(o,t,r):p(o,t))||r);return n>3&&r&&Object.defineProperty(o,t,r),r},o=this&&this.__metadata||function(e,o){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,o)};Object.defineProperty(exports,"__esModule",{value:!0}),exports.ResponseCommentsBaseDto=exports.ResponseCommentBaseDto=void 0;const t=require("class-transformer"),s=require("../../dto");class UserDto{}e([(0,t.Expose)(),o("design:type",String)],UserDto.prototype,"uid",void 0),e([(0,t.Expose)(),o("design:type",String)],UserDto.prototype,"name",void 0);class ResponseCommentBaseDto{}exports.ResponseCommentBaseDto=ResponseCommentBaseDto,e([(0,t.Expose)(),o("design:type",Number)],ResponseCommentBaseDto.prototype,"id",void 0),e([(0,t.Expose)(),o("design:type",Object)],ResponseCommentBaseDto.prototype,"target",void 0),e([(0,t.Expose)(),o("design:type",Number)],ResponseCommentBaseDto.prototype,"target_id",void 0),e([(0,t.Expose)(),o("design:type",Number)],ResponseCommentBaseDto.prototype,"parent_id",void 0),e([(0,t.Expose)(),o("design:type",Number)],ResponseCommentBaseDto.prototype,"group_id",void 0),e([(0,t.Expose)(),o("design:type",Number)],ResponseCommentBaseDto.prototype,"depth",void 0),e([(0,t.Expose)(),o("design:type",Number)],ResponseCommentBaseDto.prototype,"sort",void 0),e([(0,t.Expose)(),(0,t.Type)(()=>UserDto),o("design:type",UserDto)],ResponseCommentBaseDto.prototype,"user",void 0),e([(0,t.Expose)(),o("design:type",String)],ResponseCommentBaseDto.prototype,"content",void 0),e([(0,t.Expose)(),o("design:type",Number)],ResponseCommentBaseDto.prototype,"cnt_likes",void 0),e([(0,t.Expose)(),o("design:type",Number)],ResponseCommentBaseDto.prototype,"cnt_replies",void 0),e([(0,t.Expose)(),o("design:type",Date)],ResponseCommentBaseDto.prototype,"created_at",void 0),e([(0,t.Expose)(),o("design:type",Date)],ResponseCommentBaseDto.prototype,"updated_at",void 0),e([(0,t.Expose)(),o("design:type",Date)],ResponseCommentBaseDto.prototype,"deleted_at",void 0);class ResponseCommentsBaseDto{}exports.ResponseCommentsBaseDto=ResponseCommentsBaseDto,e([(0,t.Expose)(),(0,t.Type)(()=>ResponseCommentBaseDto),o("design:type",Array)],ResponseCommentsBaseDto.prototype,"items",void 0),e([(0,t.Expose)(),(0,t.Type)(()=>s.PaginationDto),o("design:type",s.PaginationDto)],ResponseCommentsBaseDto.prototype,"pagination",void 0);
|
|
1
|
+
var e=this&&this.__decorate||function(e,o,t,s){var p,n=arguments.length,r=n<3?o:null===s?s=Object.getOwnPropertyDescriptor(o,t):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,o,t,s);else for(var i=e.length-1;i>=0;i--)(p=e[i])&&(r=(n<3?p(r):n>3?p(o,t,r):p(o,t))||r);return n>3&&r&&Object.defineProperty(o,t,r),r},o=this&&this.__metadata||function(e,o){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,o)};Object.defineProperty(exports,"__esModule",{value:!0}),exports.ResponseCommentsBaseDto=exports.ResponseCommentBaseDto=void 0;const t=require("class-transformer"),s=require("../../dto");class UserDto{}e([(0,t.Expose)(),o("design:type",String)],UserDto.prototype,"uid",void 0),e([(0,t.Expose)(),o("design:type",String)],UserDto.prototype,"name",void 0),e([(0,t.Expose)(),o("design:type",String)],UserDto.prototype,"profile_image",void 0),e([(0,t.Expose)(),o("design:type",String)],UserDto.prototype,"info_department",void 0),e([(0,t.Expose)(),o("design:type",String)],UserDto.prototype,"info_position",void 0);class ResponseCommentBaseDto{}exports.ResponseCommentBaseDto=ResponseCommentBaseDto,e([(0,t.Expose)(),o("design:type",Number)],ResponseCommentBaseDto.prototype,"id",void 0),e([(0,t.Expose)(),o("design:type",Object)],ResponseCommentBaseDto.prototype,"target",void 0),e([(0,t.Expose)(),o("design:type",Number)],ResponseCommentBaseDto.prototype,"target_id",void 0),e([(0,t.Expose)(),o("design:type",Number)],ResponseCommentBaseDto.prototype,"parent_id",void 0),e([(0,t.Expose)(),o("design:type",Number)],ResponseCommentBaseDto.prototype,"group_id",void 0),e([(0,t.Expose)(),o("design:type",Number)],ResponseCommentBaseDto.prototype,"depth",void 0),e([(0,t.Expose)(),o("design:type",Number)],ResponseCommentBaseDto.prototype,"sort",void 0),e([(0,t.Expose)(),(0,t.Type)(()=>UserDto),o("design:type",UserDto)],ResponseCommentBaseDto.prototype,"user",void 0),e([(0,t.Expose)(),o("design:type",String)],ResponseCommentBaseDto.prototype,"content",void 0),e([(0,t.Expose)(),o("design:type",Number)],ResponseCommentBaseDto.prototype,"cnt_likes",void 0),e([(0,t.Expose)(),o("design:type",Number)],ResponseCommentBaseDto.prototype,"cnt_replies",void 0),e([(0,t.Expose)(),o("design:type",Date)],ResponseCommentBaseDto.prototype,"created_at",void 0),e([(0,t.Expose)(),o("design:type",Date)],ResponseCommentBaseDto.prototype,"updated_at",void 0),e([(0,t.Expose)(),o("design:type",Date)],ResponseCommentBaseDto.prototype,"deleted_at",void 0);class ResponseCommentsBaseDto{}exports.ResponseCommentsBaseDto=ResponseCommentsBaseDto,e([(0,t.Expose)(),(0,t.Type)(()=>ResponseCommentBaseDto),o("design:type",Array)],ResponseCommentsBaseDto.prototype,"items",void 0),e([(0,t.Expose)(),(0,t.Type)(()=>s.PaginationDto),o("design:type",s.PaginationDto)],ResponseCommentsBaseDto.prototype,"pagination",void 0);
|