1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- import { HttpMethod, Route, StatusCodes } from 'org.crazydoctor.expressts';
- import { Request, Response } from 'express';
- import ServerApp from '..';
- import { CommentsManager } from '../comments/CommentsManager';
- class PostInheritedComments extends Route {
- protected action = (req: Request, res: Response): any => {
- const params = req.body;
- const query = JSON.parse(params.query);
- if(ServerApp.SourcesUpdating) {
- res.status(StatusCodes.CONFLICT).send('Sources are being updated.');
- return;
- }
- const inheritedComments: any = {};
- const querySize = Object.keys(query).length;
- let index = 0;
- for(const className of Object.keys(query)) {
- const obj = query[className];
- const root = obj.root;
- const properties = obj.properties;
-
- CommentsManager.getCommentsByClass(root, className, properties).then((result) => {
- if(!result.success) {
- res.status(StatusCodes.INTERNAL_SERVER_ERROR).send('Internal server error');
- return;
- }
- const commentsObj: any = {};
- result.comments?.forEach((comment) => {
- result.comments?.forEach((comment) => {
- commentsObj[comment.propertyName] = comment;
- });
- });
- inheritedComments[className] = commentsObj;
- index++;
- if(index === querySize)
- res.status(StatusCodes.OK).send(JSON.stringify(inheritedComments));
- });
- }
- };
- protected method = HttpMethod.POST;
- protected order = 8;
- protected route = '/getInheritedComments';
- }
- export default PostInheritedComments;
|