Commit 7576ef03 authored by nanahira's avatar nanahira

fix deck info history

parent 1db62e1f
Pipeline #2942 passed with stages
in 3 minutes and 46 seconds
...@@ -2,6 +2,7 @@ import { ...@@ -2,6 +2,7 @@ import {
Body, Body,
Controller, Controller,
Get, Get,
NotFoundException,
Param, Param,
Post, Post,
Query, Query,
...@@ -153,12 +154,11 @@ export class AppController { ...@@ -153,12 +154,11 @@ export class AppController {
return result; return result;
} }
@Get('deckinfo') @Get('deckinfo')
async getDeckInfo(@Query() query, @Res() res: express.Response) { async getDeckInfo(@Query() query) {
if (!query.name) { if (!query.name) {
res.status(404).send('deck name is required!'); throw new NotFoundException('deck name is required!');
} }
const result = await this.appService.getDeckInfo(query); return await this.appService.getDeckInfo(query);
res.status(result.code).json(result);
} }
@Post('upload') @Post('upload')
uploadFile(@Req() req: express.Request, @Res() res: express.Response) { uploadFile(@Req() req: express.Request, @Res() res: express.Response) {
......
import { Injectable } from '@nestjs/common'; import { Injectable, NotFoundException } from '@nestjs/common';
import { InjectConnection, InjectEntityManager } from '@nestjs/typeorm'; import { InjectConnection, InjectEntityManager } from '@nestjs/typeorm';
import { import {
Brackets, Brackets,
...@@ -35,6 +35,7 @@ import { DeckDemo } from './entities/mycard/DeckDemo'; ...@@ -35,6 +35,7 @@ import { DeckDemo } from './entities/mycard/DeckDemo';
import { Deck } from './entities/mycard/Deck'; import { Deck } from './entities/mycard/Deck';
import { Ads } from './entities/mycard/Ads'; import { Ads } from './entities/mycard/Ads';
import { QueryDeepPartialEntity } from 'typeorm/query-builder/QueryPartialEntity'; import { QueryDeepPartialEntity } from 'typeorm/query-builder/QueryPartialEntity';
import { DeckInfoOrHistory } from './entities/mycard/DeckInfoOrHistory';
const attrOffset = 1010; const attrOffset = 1010;
const raceOffset = 1020; const raceOffset = 1020;
...@@ -1173,10 +1174,10 @@ export class AppService { ...@@ -1173,10 +1174,10 @@ export class AppService {
async getDeckInfo(query: any) { async getDeckInfo(query: any) {
const name: string = query.name; const name: string = query.name;
const version = query.version; const version = query.version;
let deck: any; let deck: DeckInfoOrHistory;
if (version) { if (version) {
deck = await this.mcdb deck = await this.mcdb
.getRepository(DeckInfo) .getRepository(DeckInfoHistory)
.createQueryBuilder() .createQueryBuilder()
.where('name = :name', { name }) .where('name = :name', { name })
.andWhere('id = :id', { id: parseInt(version) }) .andWhere('id = :id', { id: parseInt(version) })
...@@ -1191,9 +1192,10 @@ export class AppService { ...@@ -1191,9 +1192,10 @@ export class AppService {
.getOne(); .getOne();
} }
if (!deck) { if (!deck) {
return { throw new NotFoundException({
code: 404, code: 404,
}; message: 'deck not found.',
});
} }
const resName = deck.name; const resName = deck.name;
const history = await this.mcdb const history = await this.mcdb
...@@ -1413,7 +1415,9 @@ export class AppService { ...@@ -1413,7 +1415,9 @@ export class AppService {
deckInfoHistory.name = name; deckInfoHistory.name = name;
deckInfoHistory.content = contentStr; deckInfoHistory.content = contentStr;
deckInfoHistory.end_time = now; deckInfoHistory.end_time = now;
await db.getRepository(DeckInfoHistory).save(deckInfoHistory); this.log.log(
await db.getRepository(DeckInfoHistory).save(deckInfoHistory),
);
} catch (e) { } catch (e) {
this.log.error(`Failed to submit deck info ${name}: ${e.toString()}`); this.log.error(`Failed to submit deck info ${name}: ${e.toString()}`);
code = 500; code = 500;
......
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm'; import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
import { DeckInfoOrHistory } from './DeckInfoOrHistory';
@Entity('deck_info', { schema: 'public' }) @Entity('deck_info', { schema: 'public' })
export class DeckInfo { export class DeckInfo implements DeckInfoOrHistory {
@PrimaryGeneratedColumn({ type: 'integer', name: 'id' }) @PrimaryGeneratedColumn({ type: 'integer', name: 'id' })
id: number; id: number;
......
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm'; import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
import { DeckInfoOrHistory } from './DeckInfoOrHistory';
@Entity('deck_info_history', { schema: 'public' }) @Entity('deck_info_history', { schema: 'public' })
export class DeckInfoHistory { export class DeckInfoHistory implements DeckInfoOrHistory {
@PrimaryGeneratedColumn({ type: 'integer', name: 'id' }) @PrimaryGeneratedColumn({ type: 'integer', name: 'id' })
id: number; id: number;
......
export interface DeckInfoOrHistory {
id: number;
name: string;
content: string;
start_time: Date;
end_time: Date;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment