Skip to content

Commit

Permalink
Merge pull request #338 from TogetherCrew/debug-upv1
Browse files Browse the repository at this point in the history
Debug upv1
  • Loading branch information
Behzad-rabiei authored Apr 9, 2024
2 parents 091890e + 338e6a0 commit 24c6ba4
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 15 deletions.
9 changes: 0 additions & 9 deletions src/middlewares/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ async function getCommunity(req: Request, reject: Function): Promise<any | null>
let communityId: string | null = null,
platformId: string | null = null;

console.log(ids);
console.log('***********');

if (ids.communityId) {
communityId = ids.communityId;
} else if (ids.community) {
Expand All @@ -51,9 +48,6 @@ async function getCommunity(req: Request, reject: Function): Promise<any | null>
platformId = ids.platformId;
}

console.log(typeof communityId, communityId);
console.log(typeof platformId, platformId);

if (communityId !== null && !Types.ObjectId.isValid(communityId)) {
reject(new ApiError(httpStatus.BAD_REQUEST, 'Invalid communityId'));
}
Expand All @@ -67,13 +61,11 @@ async function getCommunity(req: Request, reject: Function): Promise<any | null>
req.community = community;
return community;
} else {
console.log(1);
reject(new ApiError(httpStatus.NOT_FOUND, 'Community not found!'));
}
} else if (platformId) {
const platform = await platformService.getPlatformById(new Types.ObjectId(platformId));
if (!platform) {
console.log(2);
reject(new ApiError(httpStatus.NOT_FOUND, 'Platform not found!'));
return null;
}
Expand All @@ -84,7 +76,6 @@ async function getCommunity(req: Request, reject: Function): Promise<any | null>
req.community = community;
return community;
} else {
console.log(3);
reject(new ApiError(httpStatus.NOT_FOUND, 'Community not found!'));
}
}
Expand Down
21 changes: 16 additions & 5 deletions src/routes/v1/announcement.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,36 @@ import RabbitMQ, { Event } from '@togethercrew.dev/tc-messagebroker';
const router = express.Router();

router.post(
'',
'/:platformId',
auth('admin'),
validate(announcementValidation.createAnnouncement),
announcementController.createAnnouncement,
);
router.get(
'',
'/:platformId',
auth('admin'),
validate(announcementValidation.getAnnouncements),
announcementController.getAnnouncements,
);
router.get('/:announcementId', auth('admin'), announcementController.getOneAnnouncement);
router.get(
'/:platformId/:announcementId',
auth('admin'),
validate(announcementValidation.getOneAnnouncement),
announcementController.getOneAnnouncement,
);

router.patch(
'/:announcementId',
'/:platformId/:announcementId',
auth('admin'),
validate(announcementValidation.updateAnnouncement),
announcementController.updateAnnouncement,
);
router.delete('/:announcementId', auth('admin'), announcementController.deleteAnnouncement);
router.delete(
'/:platformId/:announcementId',
auth('admin'),
validate(announcementValidation.deleteAnnouncement),
announcementController.deleteAnnouncement,
);

RabbitMQ.onEvent(Event.SERVER_API.ANNOUNCEMENT_SAFETY_MESSAGE, announcementController.onSafetyMessageEvent);

Expand Down
2 changes: 1 addition & 1 deletion src/routes/v1/memberActivity.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import express from 'express';
import { memberActivityController } from '../../controllers';
import { memberActivityValidation } from '../../validations';

import { validate, auth, platform } from '../../middlewares';
import { validate, auth } from '../../middlewares';
const router = express.Router();

// Routes
Expand Down
33 changes: 33 additions & 0 deletions src/validations/announcement.validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import Joi from 'joi';
import { objectId } from './custom.validation';

const createAnnouncement = {
params: Joi.object()
.required()
.keys({
platformId: Joi.string().custom(objectId),
}),
body: Joi.object().keys({
title: Joi.string(),
communityId: Joi.string().custom(objectId).required(),
Expand All @@ -27,6 +32,11 @@ const createAnnouncement = {
};

const updateAnnouncement = {
params: Joi.object()
.required()
.keys({
platformId: Joi.string().custom(objectId),
}),
body: Joi.object().keys({
title: Joi.string(),
scheduledAt: Joi.date().greater('now').iso().description('ISO date string. UTC time zone'),
Expand All @@ -48,6 +58,11 @@ const updateAnnouncement = {
};

const getAnnouncements = {
params: Joi.object()
.required()
.keys({
platformId: Joi.string().custom(objectId),
}),
query: Joi.object().keys({
communityId: Joi.string().custom(objectId).required(),
sortBy: Joi.string(),
Expand All @@ -66,8 +81,26 @@ const getAnnouncements = {
}),
};

const getOneAnnouncement = {
params: Joi.object()
.required()
.keys({
platformId: Joi.string().custom(objectId),
}),
};

const deleteAnnouncement = {
params: Joi.object()
.required()
.keys({
platformId: Joi.string().custom(objectId),
}),
};

export default {
createAnnouncement,
updateAnnouncement,
getAnnouncements,
getOneAnnouncement,
deleteAnnouncement,
};

0 comments on commit 24c6ba4

Please sign in to comment.