Skip to content
Snippets Groups Projects
Select Git revision
  • 46efed82ace93985dac0e3360b7d9f322455f22e
  • main default protected
  • master
  • Rasp2
  • rasp4
  • Rasp3
  • Rasp1
7 results

test0831.py

Blame
  • my.js 2.20 KiB
    import { Router } from 'express';
    import myService from '../services/myService.js';
    import authMiddleware from '../middlewares/authMiddleware.js';
    import { wrapAsync } from '../utils.js';
    import { ReportableError } from '../errors.js';
    
    const myRouter = Router();
    
    myRouter.get(
      '/pc',
      authMiddleware,
      wrapAsync(async (req, res) => {
        const userId = req.user?.userId;
    
        if (!userId) {
          throw new ReportableError(400, '유효한 사용자 정보가 없습니다.');
        }
    
        const data = await myService.getUserPCs(userId);
        res.sendResponse('', 200, data);
      })
    );
    
    myRouter.patch(
      '/pc/:combinationId/name',
      authMiddleware,
      wrapAsync(async (req, res) => {
        const { combinationId } = req.params;
        const { newName } = req.body;
        const userId = req.user.id;
    
        if (!newName || typeof newName !== 'string') {
          throw new ReportableError(400, '유효한 새로운 이름이 필요합니다.');
        }
    
        const result = await myService.updateCombinationName(userId, combinationId, newName);
    
        return res.status(200).json(result);
      })
    );
    
    myRouter.get(
      '/registration-code',
      authMiddleware,
      wrapAsync(async (req, res) => {
        const userId = req.user?.userId;
    
        if (!userId) {
          throw new ReportableError(400, '사용자 ID가 없습니다.');
        }
    
        const code = await myService.createRegistrationCode(userId);
        res.sendResponse('', 200, code);
      })
    );
    
    myRouter.get(
      '/registration-code/:code',
      authMiddleware,
      wrapAsync(async (req, res) => {
        const { code } = req.params;
    
        if (!code) {
          throw new ReportableError(400, '코드가 필요합니다.');
        }
    
        const data = await myService.getCombinationId(code);
        res.sendResponse('', 200, data);
      })
    );
    
    myRouter.post(
      '/',
      wrapAsync(async (req, res) => {
        const authorizationHeader = req.headers['authorization'];
        const code = authorizationHeader?.split(' ')[1];
    
        if (!code) {
          throw new ReportableError(401, '코드가 필요합니다.');
        }
    
        const { xml } = req.body;
    
        if (!xml) {
          throw new ReportableError(400, 'XML 데이터가 필요합니다.');
        }
    
        await myService.saveDocument(code, xml);
        res.sendResponse('', 200, {});
      })
    );
    
    export default myRouter;