diff --git a/backend/src/modules/rest/auth/app/auth.app.service.ts b/backend/src/modules/rest/auth/app/auth.app.service.ts index 37faf41..0d2c3cc 100644 --- a/backend/src/modules/rest/auth/app/auth.app.service.ts +++ b/backend/src/modules/rest/auth/app/auth.app.service.ts @@ -12,7 +12,7 @@ import configs from 'configs'; import { IDecodedUser, IUserRoles } from 'interfaces/user'; import { Secret } from 'jsonwebtoken'; import { pick } from 'lodash'; -import { NOTIFICATION_TOPIC } from 'shared/pushNotification'; +import { NOTIFICATION_TOPIC, PushNotification } from 'shared/pushNotification'; const login = async ( body: IReq @@ -54,7 +54,13 @@ const login = async ( if (userExists) { const checkFcm = userExists.fcmTokens.filter(v => v.device !== fcmToken.device); if (checkFcm.length) { - //Todo: send notification to existing device + // send notification to existing device + PushNotification.send(checkFcm, { + type: 'app-update', + title: 'New device login!', + body: `Device Name: ${fcmToken.device}`, + data: { screenId: 'setting-modal' }, + }); } const fcmTokens = [...checkFcm, fcmToken]; diff --git a/backend/src/modules/rest/user/app/user.app.controller.ts b/backend/src/modules/rest/user/app/user.app.controller.ts index 2acacb7..7165c92 100644 --- a/backend/src/modules/rest/user/app/user.app.controller.ts +++ b/backend/src/modules/rest/user/app/user.app.controller.ts @@ -3,6 +3,16 @@ import { sendResponse } from 'shared/sendResponse'; import { AppUserService } from './user.app.service'; // -------------------------------get------------------------------- +const getUpdatedInfo = catchAsync(async (req, res) => { + const data = await AppUserService.getUpdatedInfo(req.user); + + sendResponse(res, { + statusCode: 200, + success: true, + message: 'Retrieved user updated info successfully!!!', + data, + }); +}); // ----------------------------------add---------------------------- const refreshFcmToken = catchAsync(async (req, res) => { @@ -58,6 +68,7 @@ const removeOtherUser = catchAsync(async (req, res) => { }); export const AppUserController = { + getUpdatedInfo, refreshFcmToken, addSkill, updateUser, diff --git a/backend/src/modules/rest/user/app/user.app.routes.ts b/backend/src/modules/rest/user/app/user.app.routes.ts index f39d0e6..c7c2c38 100644 --- a/backend/src/modules/rest/user/app/user.app.routes.ts +++ b/backend/src/modules/rest/user/app/user.app.routes.ts @@ -6,6 +6,8 @@ import { AppUserController } from './user.app.controller'; const router = express.Router(); +router.get('/updated-info', auth('user', 'userN'), AppUserController.getUpdatedInfo); + router.post( '/refresh-fcm-token', auth('user', 'userN'), @@ -32,7 +34,6 @@ router.delete( validateRequest(AppUserValidation.removeSkillZodSchema), AppUserController.removeSkill ); - router.delete( '/remove-other-user', auth('user', 'userN'), diff --git a/backend/src/modules/rest/user/app/user.app.service.ts b/backend/src/modules/rest/user/app/user.app.service.ts index 7eaba4a..29f9ba7 100644 --- a/backend/src/modules/rest/user/app/user.app.service.ts +++ b/backend/src/modules/rest/user/app/user.app.service.ts @@ -6,7 +6,49 @@ import { NOTIFICATION_TOPIC } from 'shared/pushNotification'; import ApiError from 'errors/ApiError'; // ---------------get---------------------- +const getUpdatedInfo = async (decodedUser: IDecodedUser) => { + const { _id } = decodedUser; + const userData = await AppUser.findById(_id) + .select('-_id fcmTokens fullName imageUrl coverUrl interests badges upVotes downVotes isBanned') + .lean(); + // todo: remove this dummy data with proper data + const materialSections = [ + { + title: 'English basic for beginner', + thumbnail: + 'https://t3.ftcdn.net/jpg/03/70/42/66/360_F_370426690_Pejt9KxjWTHPklsKwripaxr0iA17zupF.jpg', + }, + { + title: 'English for web developer', + thumbnail: + 'https://www.fluentu.com/blog/english/wp-content/uploads/sites/4/2022/08/how-to-speak-english-fluently-1024x683.jpg', + }, + { + title: 'Advance English grammar', + thumbnail: + 'https://www.21kschool.com/blog/wp-content/uploads/2022/10/The-Importance-of-Grammar-in-Learning-the-English-Language.png', + }, + { + title: 'English for daily conversation', + thumbnail: + 'https://t3.ftcdn.net/jpg/03/70/42/66/360_F_370426690_Pejt9KxjWTHPklsKwripaxr0iA17zupF.jpg', + }, + { + title: 'English for Business Communication', + thumbnail: + 'https://www.fluentu.com/blog/english/wp-content/uploads/sites/4/2022/08/how-to-speak-english-fluently-1024x683.jpg', + }, + ]; + + return { + userData: { + ...userData, + fcmTokens: userData?.fcmTokens.map(t => ({ token: t.token, device: t.device })), + }, + materialSections, + }; +}; // -------------------add------------------ const refreshFcmToken = async (decodedUser: IDecodedUser, fcmToken: IFcmToken): Promise => { const { _id } = decodedUser; @@ -71,6 +113,7 @@ const removeOtherUser = async (decodedUser: IDecodedUser, device: string): Promi }; export const AppUserService = { + getUpdatedInfo, refreshFcmToken, addSkill, updateUser,