Skip to content

Commit

Permalink
Merge pull request #6 from graywenn/fix/getCurInform_addType
Browse files Browse the repository at this point in the history
addType
  • Loading branch information
Mr-Xiao-Zhang authored Jun 8, 2022
2 parents 10a9604 + 22c48ec commit 843eec7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
14 changes: 7 additions & 7 deletions src/controllers/inform.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Body, Controller, Get, Post } from '@nestjs/common';
import { Body, Controller, Delete, Get, Param, Post, Put } from '@nestjs/common';
import { InformService } from '@services/inform.service';

@Controller('inform')
Expand All @@ -10,22 +10,22 @@ export class InformController {
return await this.informService.getInforms();
}

@Get('/getCur')
@Get('/getCurrent')
async getCurInform() {
return await this.informService.getCurInform();
return await this.informService.getCurrentInform();
}

@Post('/add')
async addInform(@Body() body) {
return await this.informService.addInform(body);
}

@Post('/del')
async delInform(@Body() body) {
return await this.informService.delInform(body);
@Delete('/delete/:id')
async delInform(@Param('id') id: string) {
return await this.informService.deleteInform(id);
}

@Post('/modify')
@Put('/modify')
async modifyInform(@Body() body) {
return await this.informService.modifyInform(body);
}
Expand Down
12 changes: 6 additions & 6 deletions src/core/files.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export default class FileData {
return <IInfromData[]>JSON.parse(data);
};

static writeInfromFile = async (data: any) => {
static writeInfromFile = async (data: IInfromData) => {
const datas = await FileData.readInfromFile();
datas.push(data);
return await FileData.tryCatchWriteFile(
Expand All @@ -168,10 +168,10 @@ export default class FileData {
);
};

static delInfromFile = async (data: any) => {
static deleteInfromFile = async (id: string) => {
const datas = await FileData.readInfromFile();
const resultData = datas.filter((item) => {
if (item.id !== data.id) {
if (item.id !== id) {
return item;
}
});
Expand All @@ -182,7 +182,7 @@ export default class FileData {
);
};

static modifyInform = async (data: any) => {
static modifyInform = async (data: IInfromData) => {
const datas = await FileData.readInfromFile();
const index = datas.findIndex((item) => {
return item.id === data.id;
Expand All @@ -195,7 +195,7 @@ export default class FileData {
);
};

static getCurInform = async () => {
static getCurrentInform = async () => {
const datas = await FileData.readInfromFile();
const today = moment().format('YYYY-MM-DD');
const resultData = datas.filter((item) => {
Expand All @@ -204,7 +204,7 @@ export default class FileData {
}
});
resultData.sort((a, b) => {
return a.weight - b.weight;
return b.weight - a.weight;
});
return resultData;
};
Expand Down
8 changes: 4 additions & 4 deletions src/services/inform.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export class InformService {
/**
* 获取当前通知
*/
async getCurInform() {
const informs = await FileData.getCurInform();
async getCurrentInform() {
const informs = await FileData.getCurrentInform();
return informs;
}

Expand All @@ -32,8 +32,8 @@ export class InformService {
/**
* 删除通知
*/
async delInform(data: any) {
const informs = await FileData.delInfromFile(data);
async deleteInform(id: string) {
const informs = await FileData.deleteInfromFile(id);
return informs;
}

Expand Down

0 comments on commit 843eec7

Please sign in to comment.