-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/develop' into Feat/#40
- Loading branch information
Showing
12 changed files
with
118 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,4 +64,7 @@ export default { | |
|
||
// 상황 | ||
SITUATIONS_GET_SUCCESS: '상황 불러오기 성공', | ||
|
||
// 배너 | ||
READ_BANNER_SUCCESS: '배너 불러오기 성공', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Request, Response } from 'express'; | ||
import { message, statusCode } from '../constants'; | ||
import { fail, success } from '../constants/response'; | ||
|
||
import { slackMessage } from '../modules/slackMessage'; | ||
import { sendMessageToSlack } from '../modules/slackAPI'; | ||
import bannerService from '../service/bannerService'; | ||
|
||
/** | ||
* @route GET /mission/banner | ||
* @desc Get banner | ||
* @access Public | ||
*/ | ||
const getBanner = async (req: Request, res: Response) => { | ||
const userId = req.body.userId; | ||
try { | ||
const data = await bannerService.getBanner(userId); | ||
return res.status(statusCode.OK).send(success(statusCode.OK, message.READ_BANNER_SUCCESS, data)); | ||
} catch (error) { | ||
if (error === 400) { | ||
res.status(statusCode.BAD_REQUEST).send(fail(statusCode.BAD_REQUEST, message.INVALID_DATE_TYPE)); | ||
return; | ||
} | ||
const errorMessage: string = slackMessage(req.method.toUpperCase(), req.originalUrl, error, req.body.user?.id); | ||
sendMessageToSlack(errorMessage); | ||
res.status(statusCode.INTERNAL_SERVER_ERROR).send(fail(statusCode.INTERNAL_SERVER_ERROR, message.INTERNAL_SERVER_ERROR)); | ||
} | ||
}; | ||
|
||
export default { | ||
getBanner, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const KR_TIME_DIFF = 9 * 60 * 60 * 1000; | ||
|
||
const getKoreanTime = async () => { | ||
const curr = new Date(); | ||
const utc = curr.getTime() + curr.getTimezoneOffset() * 60 * 1000; | ||
const kr_curr = new Date(utc + KR_TIME_DIFF); | ||
return kr_curr; | ||
}; | ||
|
||
export default getKoreanTime; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { PrismaClient } from '@prisma/client'; | ||
const prisma = new PrismaClient(); | ||
|
||
const getRandomBanner = async (bannerCategory: string) => { | ||
const banners = await prisma.banner.findMany({ | ||
where: { | ||
banner_category: bannerCategory, | ||
}, | ||
select: { | ||
title: true, | ||
image: true, | ||
} | ||
}); | ||
|
||
return shuffleAndSelect(banners); | ||
}; | ||
|
||
const shuffleAndSelect = (array: Array<{ title: string; image: string }>) => { | ||
const randomArray = array.sort(() => Math.random() - 0.5); | ||
return randomArray[0]; | ||
}; | ||
|
||
export default getRandomBanner; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Router } from 'express'; | ||
import { auth } from '../middlewares'; | ||
import { bannerController } from '../controllers'; | ||
|
||
const router: Router = Router(); | ||
|
||
router.get('/', auth, bannerController.getBanner); | ||
|
||
export default router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { PrismaClient } from '@prisma/client'; | ||
import getRandomBanner from '../modules/shuffleBanner'; | ||
import getKoreanTime from '../modules/koreanTimeConverter'; | ||
const prisma = new PrismaClient(); | ||
|
||
const getBanner = async (userId: number) => { | ||
const dailyMissions = await prisma.mission.findMany({ | ||
where: { | ||
user_id: userId, | ||
action_date: await getKoreanTime(), | ||
}, | ||
select: { | ||
completion_status: true, | ||
}, | ||
}); | ||
|
||
const notYetCount = dailyMissions.filter((x) => x.completion_status?.includes('NOTYET')).length; | ||
if (notYetCount > 0 || dailyMissions.length === 0) { | ||
return getRandomBanner('NOTYET'); | ||
} | ||
return getRandomBanner('FINISH'); | ||
}; | ||
|
||
export default { | ||
getBanner, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters