Commit 5e4ce051 authored by nanahira's avatar nanahira

config set and get

parent 3db70844
Pipeline #1522 passed with stages
in 7 minutes and 33 seconds
import { Controller, Get, Query, Res } from '@nestjs/common';
import {Body, Controller, Get, Post, Query, Res} from '@nestjs/common';
import express from 'express';
import { AppService } from './app.service';
import { UserInfo } from './entities/mycard/UserInfo';
......@@ -38,4 +38,9 @@ export class AppController {
) {
return await this.appService.getReport(fromDate, toDate);
}
@Post('activity')
async updateActivity(@Body() body: any) {
return await this.updateActivity(body);
}
}
......@@ -11,6 +11,7 @@ import { getStringValueByMysticalNumber } from './CardInfo';
import * as moment from 'moment';
import { BattleHistory } from './entities/mycard/BattleHistory';
import _ from 'underscore';
import { SiteConfig } from './entities/mycard/SiteConfig';
const attrOffset = 1010;
const raceOffset = 1020;
......@@ -378,4 +379,32 @@ export class AppService {
return null;
}
}
private async getSiteConfig(configKey: string) {
const configObject = await this.mcdb
.getRepository(SiteConfig)
.findOneOrFail({
select: ['configValue'],
where: [configKey],
});
return configObject.configValue;
}
private async updateSiteConfig(configKey: string, configValue: string) {
await this.mcdb
.getRepository(SiteConfig)
.update({ configKey }, { configValue });
}
async updateActivity(body: any) {
const { start, end, max, name } = body;
const activityStr = JSON.stringify({ start, end, max, name });
try {
await this.updateSiteConfig('activity', activityStr);
return { code: 200 };
} catch (e) {
this.log.warn(
`Failed to update activity to ${activityStr}: ${e.toString()}`,
);
return { code: 500 };
}
}
}
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