Skip to content

Commit

Permalink
feat: add notice scheduler, scripts-dev/prod mod
Browse files Browse the repository at this point in the history
  • Loading branch information
ptyoiy committed Mar 14, 2024
1 parent de02da3 commit 8f9abf5
Show file tree
Hide file tree
Showing 26 changed files with 280 additions and 103 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,4 @@ jobs:
git reset --hard ${{ github.ref }}
git pull --force origin ${{ github.ref }}
npm i
npm run build
node createFolders.js
lsof -i :7070 | awk 'NR!=1 {print $2}' | xargs -r kill
nohup node dist/index.js > ../app.log 2>&1 &
npm run start:prod
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
script-shell = "C:\\Program Files\\PowerShell\\7\\pwsh.exe"
14 changes: 8 additions & 6 deletions adminPage/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@ import { ComponentLoader } from 'adminjs';
import path from 'path';
import * as url from 'url';

const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
const __url = process.env.NODE_ENV === 'development' ? '.' : '../../../adminPage/components';
const __dirname = url.fileURLToPath(new URL(__url, import.meta.url));
console.log({__url, __dirname, env: process.env.NODE_ENV});
export const componentLoader = new ComponentLoader();

const add = (componentName: string, url: string): string =>
componentLoader.add(componentName, path.join(__dirname, url));

export const Components = {
Dashboard: add('Dashboard', './dashboard/Dashboard.js'),
event_list: add('EventList', './event/EventList.js'),
event_show: add('EventShow', './event/EventShow.js'),
notice_list: add('NoticeList', './notice/NoticeList.js'),
notice_show: add('NoticeShow', './notice/NoticeShow.js'),
Dashboard: add('Dashboard', './dashboard/Dashboard.tsx'),
event_list: add('EventList', './event/EventList.tsx'),
event_show: add('EventShow', './event/EventShow.tsx'),
notice_list: add('NoticeList', './notice/NoticeList.tsx'),
notice_show: add('NoticeShow', './notice/NoticeShow.tsx'),
// event_edit: add('EventEdit', './event/EventEdit.tsx'),
// custom: add('Custom', './custom/Custom.tsx')
}
2 changes: 1 addition & 1 deletion adminPage/handlers/event.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ActionHandler, Filter, SortSetter, flat, populator } from "adminjs";
import Event from "../../models/events.js";
import { redisClient } from "../../redis/redis_server.js";
import { redisClient } from "../../redis/connect.js";
import { EventActionQueryParameters } from "./index.js";

const list: ActionHandler<any> = async (request, response, context) => {
Expand Down
15 changes: 13 additions & 2 deletions adminPage/handlers/notice.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { ActionHandler, Filter, SortSetter, flat, populator } from "adminjs";
import { Op } from "sequelize";
import Notice from "../../models/notice.js";
import { redisClient } from "../../redis/redis_server.js";
import { redisClient } from "../../redis/connect.js";
import { NoticeActionQueryParameters } from "./index.js";
import { setNoticeSchedule } from "../../redis/schedule.js";
import { INotice } from "../../models/types.js";

const list: ActionHandler<any> = async (request, response, context) => {
const { query } = request; // 요청 url의 query 부분 추출
Expand Down Expand Up @@ -80,10 +82,19 @@ const after = (action: 'edit' | 'new') => async (originalResponse, request, cont
// checking if object doesn't have any errors or is a edit action
if ((isPost && isEdit) && (hasRecord && !hasError)) {
const {priority, id} = hasRecord;
const isGeneral = priority == '일반'
const redisKeyEach = `notice:${id}`;
const redisKeyAll = `alerts:${priority == '일반' ? 'general' : 'urgent'}`;
const redisKeyAll = `alerts:${isGeneral ? 'general' : 'urgent'}`;

// 이 글 캐싱
await redisClient.set(redisKeyEach, JSON.stringify(hasRecord));
// 긴급일 경우 스케쥴러 등록
if (!isGeneral) {
const recordModel = await Notice.findOne({
where: { id }
}) as INotice;
await setNoticeSchedule(recordModel);
}
// 전체 목록 캐싱
const noticesFromDB = await Notice.findAll({
where: {
Expand Down
2 changes: 1 addition & 1 deletion controllers/alarm/alarm.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as express from "express";
import { Alarm, User } from "../../models/index.js";
import { IAlarm } from "../../models/types.js";
import { redisClient } from "../../redis/redis_server.js";
import { redisClient } from "../../redis/connect.js";

const bodyList = [
"alarm_push",
Expand Down
2 changes: 1 addition & 1 deletion controllers/common_method/user_information.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Alarm, Bookmark, BookmarkAsset, EventsLike, NoticesLike, Read, ReadAsset, User } from "../../models/index.js";
import { redisClient } from "../../redis/redis_server.js";
import { redisClient } from "../../redis/connect.js";

const EXPIRE = 3600; // 유효시간 1시간

Expand Down
2 changes: 1 addition & 1 deletion controllers/common_method/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { redisClient } from "../../redis/redis_server.js";
import { redisClient } from "../../redis/connect.js";

/*** redis get 결과물 parse해서 리턴
** get결과물이 없다면 throw error
Expand Down
2 changes: 1 addition & 1 deletion controllers/event/event_bookmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { IEventUserRequest } from "./request/request.js";
import { IBookmark } from "../../models/types.js";
import { Bookmark, BookmarkAsset, sequelize } from "../../models/index.js";
import { findObjectByPk, getEventBookmarkInfo, validateRequestBody } from "../common_method/index.js";
import { redisClient } from "../../redis/redis_server.js";
import { redisClient } from "../../redis/connect.js";

const bodyList = [
"event_id",
Expand Down
2 changes: 1 addition & 1 deletion controllers/event/event_like.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as express from "express";
import { IEventUserRequest } from "./request/request.js";
import { EventsLike,sequelize } from "../../models/index.js";
import { findObjectByPk, validateRequestBody } from "../common_method/validator.js";
import { redisClient } from "../../redis/redis_server.js";
import { redisClient } from "../../redis/connect.js";
import { getEventLikeInfo } from "../common_method/user_information.js";

const bodyList = [
Expand Down
2 changes: 1 addition & 1 deletion controllers/event/event_search.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as express from "express";
import { Event } from "../../models/index.js";
import { IEvent } from "../../models/types.js";
import { redisClient } from "../../redis/redis_server.js";
import { redisClient } from "../../redis/connect.js";
import { redisGetAndParse } from "../common_method/utils.js";

const EXPIRE = 3600; // 유효시간 1시간
Expand Down
2 changes: 1 addition & 1 deletion controllers/jwt/jwt.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Express from 'express';
import jwt from "jsonwebtoken";
import { redisClient } from '../../redis/redis_server.js';
import { redisClient } from '../../redis/connect.js';

const ACCESS_EXPIRY = '1d';
const REFRESH_EXPIRY = '7d';
Expand Down
2 changes: 1 addition & 1 deletion controllers/notice/notice_like.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { INoticeUserRequest } from "./request/request.js";
import { NoticesLike, sequelize } from "../../models/index.js";
import { findObjectByPk, validateRequestBody } from "../common_method/validator.js";
import { getNoticeLikeInfo } from "../common_method/user_information.js";
import { redisClient } from "../../redis/redis_server.js";
import { redisClient } from "../../redis/connect.js";

const bodyList = [
"notice_id",
Expand Down
2 changes: 1 addition & 1 deletion controllers/notice/notice_read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { findObjectByPk, findUser, validateRequestBody } from "../common_method/
import { Notice, Read, ReadAsset, sequelize } from "../../models/index.js";
import { IRead, IReadAsset } from "../../models/types.js";
import { Op } from "sequelize";
import { redisClient } from "../../redis/redis_server.js";
import { redisClient } from "../../redis/connect.js";
import { getNoticeReadInfo } from "../common_method/user_information.js";

const bodyList = [
Expand Down
2 changes: 1 addition & 1 deletion controllers/notice/notice_search.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as express from "express";
import { Notice } from "../../models/index.js";
import { INotice } from "../../models/types.js";
import { redisClient } from "../../redis/redis_server.js";
import { redisClient } from "../../redis/connect.js";
import { redisGetAndParse } from "../common_method/utils.js";

const EXPIRE = 3600; // 유효시간 1시간
Expand Down
2 changes: 1 addition & 1 deletion controllers/user/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import axios from "axios";
import bcrypt from "bcryptjs";
import * as express from "express";
import { User } from "../../models/index.js";
import { redisClient } from "../../redis/redis_server.js";
import { redisClient } from "../../redis/connect.js";
import { reissue } from "../jwt/jwt.js";
import { login } from "./index.js";

Expand Down
2 changes: 1 addition & 1 deletion controllers/user/major.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as express from "express";
import { findObjectByPk, validateRequestBody } from "../common_method/validator.js";
import { User } from "../../models/index.js";
import { getMajorInfo } from "../common_method/user_information.js";
import { redisClient } from "../../redis/redis_server.js";
import { redisClient } from "../../redis/connect.js";

const bodyList = [
"major"
Expand Down
2 changes: 1 addition & 1 deletion controllers/user/user.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import express from 'express';
import User from '../../models/user.js';
import { redisClient } from '../../redis/redis_server.js';
import { redisClient } from '../../redis/connect.js';
import { getEventBookmarkInfo, getEventLikeInfo, getNoticeLikeInfo, getNoticeReadInfo } from '../common_method/index.js';
import { getAlarmInfo } from '../common_method/user_information.js';
import { generate } from "../jwt/index.js";
Expand Down
10 changes: 5 additions & 5 deletions nodemon.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"watch": ["*"],
"ext": ".ts,.js",
"ignore": ["/dist"],
"exec": "npm run build && node --loader ts-node/esm ./dist/index.js"
}
"watch": ["*"],
"ext": ".ts,.js",
"ignore": ["/dist"],
"exec": "node --loader ts-node/esm index.ts"
}
Loading

0 comments on commit 8f9abf5

Please sign in to comment.