Skip to content

Commit

Permalink
fix: interaction type constants
Browse files Browse the repository at this point in the history
  • Loading branch information
Hyun-git committed Jun 29, 2024
1 parent f49dd17 commit fffc0d0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
13 changes: 9 additions & 4 deletions src/controller/meme.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import CustomError from '../errors/CustomError';
import { HttpCode } from '../errors/HttpCode';
import { CustomRequest } from '../middleware/requestedInfo';
import { IMemeCreatePayload, IMemeUpdatePayload } from '../model/meme';
import { InteractionType } from 'src/model/memeInteraction';
import * as MemeService from '../service/meme.service';
import * as UserService from '../service/user.service';
import { logger } from '../util/logger';
Expand Down Expand Up @@ -170,7 +171,7 @@ const createMemeReaction = async (req: CustomRequest, res: Response, next: NextF
const meme = req.requestedMeme;

try {
const result = await MemeService.createMemeInteraction(user, meme, 'reaction');
const result = await MemeService.createMemeInteraction(user, meme, InteractionType.REACTION);
return res.json(createSuccessResponse(HttpCode.CREATED, 'Create Meme Reaction', result));
} catch (err) {
return next(new CustomError(err.message, err.status));
Expand All @@ -182,7 +183,7 @@ const createMemeSave = async (req: CustomRequest, res: Response, next: NextFunct
const meme = req.requestedMeme;

try {
const result = await MemeService.createMemeInteraction(user, meme, 'save');
const result = await MemeService.createMemeInteraction(user, meme, InteractionType.SAVE);
return res.json(createSuccessResponse(HttpCode.CREATED, 'Crate Meme Save', result));
} catch (err) {
return next(new CustomError(err.message, err.status));
Expand All @@ -194,7 +195,11 @@ const createMemeShare = async (req: CustomRequest, res: Response, next: NextFunc
const meme = req.requestedMeme;

try {
const result: boolean = await MemeService.createMemeInteraction(user, meme, 'share');
const result: boolean = await MemeService.createMemeInteraction(
user,
meme,
InteractionType.SHARE,
);
return res.json(createSuccessResponse(HttpCode.CREATED, 'Crate Meme Share', result));
} catch (err) {
return next(new CustomError(err.message, err.status));
Expand All @@ -209,7 +214,7 @@ const createMemeWatch = async (req: CustomRequest, res: Response, next: NextFunc
// 밈 조회
// 최근 본 밈 추가
const [result, _]: [boolean, any] = await Promise.all([
MemeService.createMemeInteraction(user, meme, 'watch'),
MemeService.createMemeInteraction(user, meme, InteractionType.WATCH),
UserService.updateLastSeenMeme(user, meme),
]);

Expand Down
8 changes: 4 additions & 4 deletions src/controller/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ const getUser = async (req: CustomRequest, res: Response, next: NextFunction) =>
});

const [watch, reaction, share, save] = await Promise.all([
countInteractionType('watch'),
countInteractionType('reaction'),
countInteractionType('share'),
countInteractionType('save'),
countInteractionType(InteractionType.WATCH),
countInteractionType(InteractionType.REACTION),
countInteractionType(InteractionType.SHARE),
countInteractionType(InteractionType.SAVE),
]);

const level = getLevel(watch, reaction, share, save);
Expand Down
7 changes: 6 additions & 1 deletion src/model/memeInteraction.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import mongoose, { Schema, Types } from 'mongoose';

export type InteractionType = 'watch' | 'reaction' | 'share' | 'save';
export enum InteractionType {
WATCH = 'watch',
REACTION = 'reaction',
SHARE = 'share',
SAVE = 'save',
}

export interface IMemeInteraction {
deviceId: Types.ObjectId;
Expand Down

0 comments on commit fffc0d0

Please sign in to comment.