Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: comment_react #50

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e714904
feat(SAFE-68): Call emergency UI
orangery-me Feb 8, 2024
b557702
feat(SAFE-68): Implement API
orangery-me Feb 14, 2024
addf1ad
Merge branch 'develop' into feat/SAFE-68/Call_emergency
orangery-me Feb 14, 2024
04f5da8
feat: UI for upload posts
orangery-me Feb 18, 2024
3ceca5a
feat: set notification
orangery-me Feb 18, 2024
79a3597
fix: fix bug of implement API
orangery-me Feb 20, 2024
087a47c
fix: service accept support help signal
LeTatTuan Feb 20, 2024
df8214c
fix: service cancel support help signal
LeTatTuan Feb 21, 2024
a283288
fix: userService-getUser
ThuongHoai081 Feb 22, 2024
3478f2a
fix: validate cancel-accept service. user verify cancel-done help signal
LeTatTuan Feb 22, 2024
cc6b200
db: add user_devicetokens-change length for images help_signals table
LeTatTuan Feb 22, 2024
b562129
Merge branch 'develop' into feat/SAFE-68/Call_emergency
orangery-me Feb 23, 2024
e18d6d7
ci: deploy for hackathon
High10Hunter Feb 24, 2024
a5477d3
docs: change name for api docs
High10Hunter Feb 24, 2024
37de34e
Merge pull request #39 from dscdut/feat/safe-85-Implement-supporter-a…
LeTatTuan Feb 24, 2024
78b1111
fix: fix some bugs
orangery-me Feb 24, 2024
5565b88
fix: db/table emergency
ThuongHoai081 Feb 24, 2024
a7944dc
fix: repo-emergency
ThuongHoai081 Feb 24, 2024
1ac2990
fix: save device_token and send notif
LeTatTuan Feb 24, 2024
6ec63e8
Merge pull request #46 from dscdut/feat/SAFE-67/fcm-service
LeTatTuan Feb 24, 2024
a5469bc
feat: firebase configure
orangery-me Feb 25, 2024
8e817f2
Merge pull request #47 from dscdut/feat/SAFE-68/Call_emergency
orangery-me Feb 25, 2024
332f2b5
fix: add api sendnoitf
LeTatTuan Feb 25, 2024
10624a2
Merge pull request #48 from dscdut/feat/SAFE-67/fcm-service
LeTatTuan Feb 25, 2024
7d3eecc
fix: lint staged
High10Hunter Mar 6, 2024
cb6412f
feat: comment_react
LongTCH Mar 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .github/workflows/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ on:
push:
paths:
- '**.js'
# branches:
# - develop
branches:
- develop
- contest/gdsc-hackathon-2024
pull_request:
types: [opened, synchronize]
# branches:
# - develop
branches:
- develop
- contest/gdsc-hackathon-2024
jobs:
build:
runs-on: self-hosted
Expand Down
2 changes: 1 addition & 1 deletion backend/.lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"*.js": ["npm run lint", "git add ."]
"*.js": ["npm run lint"]
}
23 changes: 23 additions & 0 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"@babel/runtime": "^7.14.0",
"@commitlint/cli": "^17.5.0",
"@commitlint/config-conventional": "^17.4.4",
"@faker-js/faker": "^8.4.1",
"babel-eslint": "^10.1.0",
"babel-plugin-module-resolver": "^4.1.0",
"babel-plugin-transform-runtime": "^6.23.0",
Expand Down
43 changes: 43 additions & 0 deletions backend/src/core/api/comment/comment.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { ValidHttpResponse } from 'packages/handler/response/validHttp.response';
import { DEFAULT_PAGE, DEFAULT_PAGE_SIZE } from 'core/common/constants';
import { MessageDto } from 'core/common/dto';
import {
AddCommentDto,
COMMENT_PARENT_TYPE,
CommentService,
} from 'core/modules/comment';

class Controller {
constructor() {
this.commentService = CommentService;
}

createComment = async req => {
const { parentType, parentId, content } = AddCommentDto(req.body);
await this.commentService.createComment(
parentId,
parentType,
content,
req.user.payload.id,
);
return ValidHttpResponse.toOkResponse(MessageDto('Comment created'));
};

getCommentPaginationByParentIdAndType = async req => {
const parentId = req.params.id;
const page = req.query.page || DEFAULT_PAGE;
const size = req.query.size || DEFAULT_PAGE_SIZE;
const parentType = req.query.keyword || 'POST';
const data =
await this.commentService.getCommentPaginationByParentIdAndType(
parentId,
COMMENT_PARENT_TYPE[parentType],
page,
size,
);

return ValidHttpResponse.toOkResponse(data);
};
}

export const CommentController = new Controller();
29 changes: 29 additions & 0 deletions backend/src/core/api/comment/comment.resolver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Module } from 'packages/handler/Module';
import { RecordId, page, size, keyword } from 'core/common/swagger';
import { CommentController } from './comment.controller';

export const CommentResolver = Module.builder()
.addPrefix({
prefixPath: '/comments',
tag: 'comments',
module: 'CommentModule',
})
.register([
{
route: '',
method: 'post',
controller: CommentController.createComment,
body: 'AddCommentDto',
model: { $ref: 'MessageDto' },
preAuthorization: true,
},
{
route: '/:id/nested',
method: 'get',
params: [page, size, keyword, RecordId],
controller: CommentController.getCommentPaginationByParentIdAndType,
model: { $ref: 'PaginationCommentDto' },
description:
'Get list nested comments of a post or comment (Keyword POST or COMMENT)',
},
]);
16 changes: 16 additions & 0 deletions backend/src/core/api/emergency/emergency.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { EmergencyService } from 'core/modules/emergency/servicce/emergency.service';
import { ValidHttpResponse } from '../../../packages/handler/response/validHttp.response';

class Controller {
constructor() {
this.service = EmergencyService;
}

getAllEmergency = async () => {
const data = await this.service.getAllEmergency();
return ValidHttpResponse.toOkResponse(data);
};

}

export const EmergencyController = new Controller();
18 changes: 18 additions & 0 deletions backend/src/core/api/emergency/emergency.resolver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Module } from 'packages/handler/Module';
import { EmergencyController } from './emergency.controller';

export const EmergencyResolver = Module.builder()
.addPrefix({
prefixPath: '/emergency',
tag: 'emergency',
module: 'emergency',
})
.register([
{
route: '/getAllEmergency',
method: 'get',
controller: EmergencyController.getAllEmergency,
preAuthorization: true,
},

]);
1 change: 1 addition & 0 deletions backend/src/core/api/emergency/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './emergency.resolver';
50 changes: 49 additions & 1 deletion backend/src/core/api/helpSignal/helpSignal.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,46 @@ class Controller {
this.service = HelpSignalService;
}

acceptSupport = async req => {
const { helpSignalId } = req.params;
const userId = req.user.payload.id;
const data = await this.service.acceptSupport(helpSignalId, userId);
return ValidHttpResponse.toOkResponse(data);
};

cancelSupportByRescuer = async req => {
const { helpSignalId } = req.params;
const rescuerId = req.user.payload.id;
const data = await this.service.cancelSupport(helpSignalId, rescuerId);
return ValidHttpResponse.toOkResponse(data);
}

cancelSupportByUser = async req => {
const { helpSignalId, rescuerId } = req.params;
const userId = req.user.payload.id;
const data = await this.service.cancelSupport(helpSignalId, rescuerId, userId);
return ValidHttpResponse.toOkResponse(data);
}

getRescuersByHelpSignalId = async req => {
const { helpSignalId } = req.params;
const data = await this.service.getRescuersByHelpSignalId(helpSignalId);
return ValidHttpResponse.toOkResponse(data);
};

createHelpSignal = async req => {
const signal = { ...req.body, statusId: 0, userId: req.user.payload.id };
const signal = { ...req.body, userId: req.user.payload.id };
const data = await this.service.createHelpSignal(createHelpSignalDto(signal), req);
return ValidHttpResponse.toCreatedResponse(data);
}

sendNotificationToUsers = async req => {
const {helpSignalId} = req.params;
const userId = req.user.payload.id;
const data = await this.service.sendNotificationToUsers(helpSignalId, userId);
return ValidHttpResponse.toOkResponse(data);
}

findHelpSignalById = async req => {
const data = await this.service.findHelpSignalById(req.params.helpSignalId);
return ValidHttpResponse.toOkResponse(data);
Expand Down Expand Up @@ -43,6 +77,20 @@ class Controller {
return ValidHttpResponse.toOkResponse(message);
}

verifyDone = async req => {
const { helpSignalId } = req.params;
const userId = req.user.payload.id;
const data = await this.service.verifyDoneOrCancel(userId, helpSignalId, true);
return ValidHttpResponse.toOkResponse(data);
}

verifyCancel = async req => {
const { helpSignalId } = req.params;
const userId = req.user.payload.id;
const data = await this.service.verifyDoneOrCancel(userId, helpSignalId, false);
return ValidHttpResponse.toOkResponse(data);
}

}

export const HelpSignalController = new Controller();
52 changes: 51 additions & 1 deletion backend/src/core/api/helpSignal/helpSignal.resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Module } from 'packages/handler/Module';
import { createHelpSignalInterceptor } from 'core/modules/helpSignal/interceptor';
import { helpSignalId, userId, emergencyId, uploadMediaSwagger } from 'core/common/swagger';
import { MediaInterceptor } from 'core/modules/document';
import { rescuerId } from 'core/common/swagger/rescuer-id';
import { HelpSignalController } from './helpSignal.controller';

export const HelpSignalResolver = Module.builder()
Expand All @@ -21,6 +22,13 @@ export const HelpSignalResolver = Module.builder()
controller: HelpSignalController.createHelpSignal,
preAuthorization: true,
},
{
route: '/sendNoitf/:helpSignalId',
method: 'get',
params: [helpSignalId],
controller: HelpSignalController.sendNotificationToUsers,
preAuthorization: true,
},
{
route: '/getAllHelpSignals',
method: 'get',
Expand Down Expand Up @@ -64,5 +72,47 @@ export const HelpSignalResolver = Module.builder()
params: [helpSignalId],
controller: HelpSignalController.deleteHelpSignal,
preAuthorization: true,
}
},
{
route: '/:helpSignalId/acceptSupport',
method: 'post',
params: [helpSignalId],
controller: HelpSignalController.acceptSupport,
preAuthorization: true,
},
{
route: '/:helpSignalId/cancelSupportByRescuer',
method: 'post',
params: [helpSignalId],
controller: HelpSignalController.cancelSupportByRescuer,
preAuthorization: true,
},
{
route: '/:helpSignalId/cancelSupportByUser/:rescuerId',
method: 'post',
params: [helpSignalId, rescuerId],
controller: HelpSignalController.cancelSupportByUser,
preAuthorization: true,
},
{
route: '/:helpSignalId/rescuerInHelpSignal',
method: 'get',
params: [helpSignalId],
controller: HelpSignalController.getRescuersByHelpSignalId,
preAuthorization: true,
},
{
route: '/:helpSignalId/verifyDone',
method: 'patch',
params: [helpSignalId],
controller: HelpSignalController.verifyDone,
preAuthorization: true,
},
{
route: '/:helpSignalId/verifyCancel',
method: 'patch',
params: [helpSignalId],
controller: HelpSignalController.verifyCancel,
preAuthorization: true,
},
]);
11 changes: 8 additions & 3 deletions backend/src/core/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ import { ApiDocument } from 'core/config/swagger.config';
import { HelpSignalResolver } from 'core/api/helpSignal';
import { HandlerResolver } from '../../packages/handler/HandlerResolver';
import { AuthResolver } from './auth/auth.resolver';
import { EmergencyResolver } from './emergency';
import { CommentResolver } from './comment/comment.resolver';
import { UserReactResolver } from './user-react/user-react.resolver';

export const ModuleResolver = HandlerResolver
.builder()
export const ModuleResolver = HandlerResolver.builder()
.addSwaggerBuilder(ApiDocument)
.addModule([
AuthResolver,
UserResolver,
MediaResolver,
HelpSignalResolver
HelpSignalResolver,
EmergencyResolver,
CommentResolver,
UserReactResolver,
]);
38 changes: 38 additions & 0 deletions backend/src/core/api/user-react/user-react.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { ValidHttpResponse } from 'packages/handler/response/validHttp.response';
import { MessageDto } from 'core/common/dto';
import { UserReactService } from 'core/modules/user-react/service/user-react.service';
import {
AddUserReactDto,
DeleteUserReactDto,
} from 'core/modules/user-react/dto';

class Controller {
constructor() {
this.userReactService = UserReactService;
}

createUserReact = async req => {
const { reactableId, reactableType, reactType } = AddUserReactDto(
req.body,
);
await this.userReactService.createUserReact(
req.user.payload.id,
reactableId,
reactableType,
reactType,
);
return ValidHttpResponse.toOkResponse(MessageDto('UserReact created'));
};

deleteUserReact = async req => {
const { reactableType, reactableId } = DeleteUserReactDto(req.body);
await this.userReactService.deleteUserReact(
req.user.payload.id,
reactableId,
reactableType,
);
return ValidHttpResponse.toOkResponse(MessageDto('UserReact deleted'));
};
}

export const UserReactController = new Controller();
Loading
Loading