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 {
Body,
Controller,
Get,
NotFoundException,
Param,
Post,
Query,
......@@ -153,12 +154,11 @@ export class AppController {
return result;
}
@Get('deckinfo')
async getDeckInfo(@Query() query, @Res() res: express.Response) {
async getDeckInfo(@Query() query) {
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);
res.status(result.code).json(result);
return await this.appService.getDeckInfo(query);
}
@Post('upload')
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 {
Brackets,
......@@ -35,6 +35,7 @@ import { DeckDemo } from './entities/mycard/DeckDemo';
import { Deck } from './entities/mycard/Deck';
import { Ads } from './entities/mycard/Ads';
import { QueryDeepPartialEntity } from 'typeorm/query-builder/QueryPartialEntity';
import { DeckInfoOrHistory } from './entities/mycard/DeckInfoOrHistory';
const attrOffset = 1010;
const raceOffset = 1020;
......@@ -1173,10 +1174,10 @@ export class AppService {
async getDeckInfo(query: any) {
const name: string = query.name;
const version = query.version;
let deck: any;
let deck: DeckInfoOrHistory;
if (version) {
deck = await this.mcdb
.getRepository(DeckInfo)
.getRepository(DeckInfoHistory)
.createQueryBuilder()
.where('name = :name', { name })
.andWhere('id = :id', { id: parseInt(version) })
......@@ -1191,9 +1192,10 @@ export class AppService {
.getOne();
}
if (!deck) {
return {
throw new NotFoundException({
code: 404,
};
message: 'deck not found.',
});
}
const resName = deck.name;
const history = await this.mcdb
......@@ -1413,7 +1415,9 @@ export class AppService {
deckInfoHistory.name = name;
deckInfoHistory.content = contentStr;
deckInfoHistory.end_time = now;
await db.getRepository(DeckInfoHistory).save(deckInfoHistory);
this.log.log(
await db.getRepository(DeckInfoHistory).save(deckInfoHistory),
);
} catch (e) {
this.log.error(`Failed to submit deck info ${name}: ${e.toString()}`);
code = 500;
......
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
import { DeckInfoOrHistory } from './DeckInfoOrHistory';
@Entity('deck_info', { schema: 'public' })
export class DeckInfo {
export class DeckInfo implements DeckInfoOrHistory {
@PrimaryGeneratedColumn({ type: 'integer', name: 'id' })
id: number;
......
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
import { DeckInfoOrHistory } from './DeckInfoOrHistory';
@Entity('deck_info_history', { schema: 'public' })
export class DeckInfoHistory {
export class DeckInfoHistory implements DeckInfoOrHistory {
@PrimaryGeneratedColumn({ type: 'integer', name: 'id' })
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