Skip to content

Commit 3939abd

Browse files
committed
【新增】各项模型审核功能
【优化】宾馆、供应商 筛选参数
1 parent 1023b84 commit 3939abd

9 files changed

+213
-47
lines changed

ReadMe.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
基于 [Koa][1][TypeScript][2][LeanCloud][3]**Node.js 后端**项目脚手架
44

55
[![NPM Dependency](https://david-dm.org/wuhan2020/rest-api.svg)][4]
6-
[![CI Status](https://github.com/wuhan2020/WebApp/workflows/PWA%20CI/CD/badge.svg)][5]
6+
[![CI Status](https://github.com/wuhan2020/rest-api/workflows/PWA%20CI/CD/badge.svg)][5]
77

88
## 主要特性
99

@@ -26,7 +26,7 @@
2626

2727
## 本地开发
2828

29-
1. 注册 [LeanCloud][3] 账号后,发邮件给 shiy2008@gmail.com 申请协作权限(需 LeanCloud 用户名)
29+
1. 注册 [LeanCloud][3] 账号并**验证注册邮箱**,发邮件给 shiy2008@gmail.com 申请协作权限(需 LeanCloud 用户名)
3030

3131
2. 安装 [LeanCloud CLI](https://leancloud.cn/docs/leanengine_cli.html#hash1443149115)
3232

@@ -64,5 +64,5 @@ lean up
6464
[2]: https://www.typescriptlang.org/
6565
[3]: https://leancloud.cn/
6666
[4]: https://david-dm.org/wuhan2020/rest-api
67-
[5]: https://github.com/wuhan2020/WebApp/actions
67+
[5]: https://github.com/wuhan2020/rest-api/actions
6868
[6]: https://fcc-cd.tk/

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
"@types/koa-logger": "^3.1.1",
2929
"@types/koa-multer": "^1.0.0",
3030
"@types/koa-router": "^7.4.0",
31-
"@typescript-eslint/eslint-plugin": "^2.18.0",
32-
"@typescript-eslint/parser": "^2.18.0",
31+
"@typescript-eslint/eslint-plugin": "^2.19.0",
32+
"@typescript-eslint/parser": "^2.19.0",
3333
"eslint": "^6.8.0",
3434
"husky": "^4.2.1",
3535
"lint-staged": "^10.0.7",

source/controller/Clinic.ts

+28-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Object as LCObject, Query, ACL, stringify } from 'leanengine';
1+
import { Object as LCObject, Query, ACL } from 'leanengine';
22
import {
33
JsonController,
44
Post,
@@ -10,8 +10,9 @@ import {
1010
QueryParam,
1111
Param,
1212
Put,
13-
Delete,
14-
OnUndefined
13+
Patch,
14+
OnUndefined,
15+
Delete
1516
} from 'routing-controllers';
1617

1718
import { LCContext, queryPage } from '../utility';
@@ -44,18 +45,20 @@ export class ClinicController {
4445

4546
clinic = await new Clinic()
4647
.setACL(acl)
47-
.save({ ...rest, name, creator: user }, { user });
48+
.save({ ...rest, name, creator: user, verified: false }, { user });
4849

4950
return clinic.toJSON();
5051
}
5152

5253
@Get()
5354
getList(
55+
@QueryParam('verified') verified: boolean,
5456
@QueryParam('pageSize') size: number,
5557
@QueryParam('pageIndex') index: number
5658
) {
5759
return queryPage(Clinic, {
58-
include: ['creator'],
60+
include: ['creator', 'verifier'],
61+
equal: { verified },
5962
size,
6063
index
6164
});
@@ -77,13 +80,32 @@ export class ClinicController {
7780
) {
7881
let clinic = LCObject.createWithoutData('Clinic', id);
7982

80-
await clinic.save(rest, { user });
83+
await clinic.save(
84+
{ ...rest, verified: false, verifier: null },
85+
{ user }
86+
);
8187

8288
clinic = await new Query(Clinic).include('creator').get(id);
8389

8490
return clinic.toJSON();
8591
}
8692

93+
@Patch('/:id')
94+
@Authorized()
95+
@OnUndefined(204)
96+
async verify(
97+
@Ctx() { currentUser: user }: LCContext,
98+
@Param('id') id: string,
99+
@Body() { verified }: { verified: boolean }
100+
) {
101+
if (!(await RoleController.isAdmin(user))) throw new ForbiddenError();
102+
103+
await LCObject.createWithoutData('Clinic', id).save(
104+
{ verified, verifier: user },
105+
{ user }
106+
);
107+
}
108+
87109
@Delete('/:id')
88110
@Authorized()
89111
@OnUndefined(204)

source/controller/DonationRecipient.ts

+27-5
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ import {
1010
QueryParam,
1111
Param,
1212
Put,
13-
Delete,
14-
OnUndefined
13+
Patch,
14+
OnUndefined,
15+
Delete
1516
} from 'routing-controllers';
1617

1718
import { LCContext, queryPage } from '../utility';
@@ -46,18 +47,20 @@ export class DonationRecipientController {
4647

4748
donationRecipient = await new DonationRecipient()
4849
.setACL(acl)
49-
.save({ ...rest, name, creator: user }, { user });
50+
.save({ ...rest, name, creator: user, verified: false }, { user });
5051

5152
return donationRecipient.toJSON();
5253
}
5354

5455
@Get()
5556
getList(
57+
@QueryParam('verified') verified: boolean,
5658
@QueryParam('pageSize') size: number,
5759
@QueryParam('pageIndex') index: number
5860
) {
5961
return queryPage(DonationRecipient, {
60-
include: ['creator'],
62+
include: ['creator', 'verifier'],
63+
equal: { verified },
6164
size,
6265
index
6366
});
@@ -81,7 +84,10 @@ export class DonationRecipientController {
8184
'DonationRecipient',
8285
id
8386
);
84-
await donationRecipient.save(rest, { user });
87+
await donationRecipient.save(
88+
{ ...rest, verified: false, verifier: null },
89+
{ user }
90+
);
8591

8692
donationRecipient = await new Query(DonationRecipient)
8793
.include('creator')
@@ -90,6 +96,22 @@ export class DonationRecipientController {
9096
return donationRecipient.toJSON();
9197
}
9298

99+
@Patch('/:id')
100+
@Authorized()
101+
@OnUndefined(204)
102+
async verify(
103+
@Ctx() { currentUser: user }: LCContext,
104+
@Param('id') id: string,
105+
@Body() { verified }: { verified: boolean }
106+
) {
107+
if (!(await RoleController.isAdmin(user))) throw new ForbiddenError();
108+
109+
await LCObject.createWithoutData('DonationRecipient', id).save(
110+
{ verified, verifier: user },
111+
{ user }
112+
);
113+
}
114+
93115
@Delete('/:id')
94116
@Authorized()
95117
@OnUndefined(204)

source/controller/Hotel.ts

+46-10
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ import {
1010
QueryParam,
1111
Param,
1212
Put,
13-
Delete,
14-
OnUndefined
13+
Patch,
14+
OnUndefined,
15+
Delete
1516
} from 'routing-controllers';
1617

1718
import { LCContext, queryPage } from '../utility';
@@ -42,23 +43,34 @@ export class HotelController {
4243
acl.setWriteAccess(user, true),
4344
acl.setRoleWriteAccess(await RoleController.getAdmin(), true);
4445

45-
hotel = await new Hotel()
46-
.setACL(acl)
47-
.save(
48-
{ ...rest, name, coords: new GeoPoint(coords), creator: user },
49-
{ user }
50-
);
46+
hotel = await new Hotel().setACL(acl).save(
47+
{
48+
...rest,
49+
name,
50+
coords: new GeoPoint(coords),
51+
creator: user,
52+
verified: false
53+
},
54+
{ user }
55+
);
5156

5257
return hotel.toJSON();
5358
}
5459

5560
@Get()
5661
getList(
62+
@QueryParam('verified') verified: boolean,
63+
@QueryParam('province') province: string,
64+
@QueryParam('city') city: string,
65+
@QueryParam('district') district: string,
66+
@QueryParam('name') name: string,
5767
@QueryParam('pageSize') size: number,
5868
@QueryParam('pageIndex') index: number
5969
) {
6070
return queryPage(Hotel, {
61-
include: ['creator'],
71+
include: ['creator', 'verifier'],
72+
equal: { verified, province, city, district },
73+
contains: { name },
6274
size,
6375
index
6476
});
@@ -80,13 +92,37 @@ export class HotelController {
8092
) {
8193
let hotel = LCObject.createWithoutData('Hotel', id);
8294

83-
await hotel.save({ ...rest, coords: new GeoPoint(coords) }, { user });
95+
await hotel.save(
96+
{
97+
...rest,
98+
coords: new GeoPoint(coords),
99+
verified: false,
100+
verifier: null
101+
},
102+
{ user }
103+
);
84104

85105
hotel = await new Query(Hotel).include('creator').get(id);
86106

87107
return hotel.toJSON();
88108
}
89109

110+
@Patch('/:id')
111+
@Authorized()
112+
@OnUndefined(204)
113+
async verify(
114+
@Ctx() { currentUser: user }: LCContext,
115+
@Param('id') id: string,
116+
@Body() { verified }: { verified: boolean }
117+
) {
118+
if (!(await RoleController.isAdmin(user))) throw new ForbiddenError();
119+
120+
await LCObject.createWithoutData('Hotel', id).save(
121+
{ verified, verifier: user },
122+
{ user }
123+
);
124+
}
125+
90126
@Delete('/:id')
91127
@Authorized()
92128
@OnUndefined(204)

source/controller/Logistics.ts

+27-5
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ import {
1010
QueryParam,
1111
Param,
1212
Put,
13-
Delete,
14-
OnUndefined
13+
Patch,
14+
OnUndefined,
15+
Delete
1516
} from 'routing-controllers';
1617

1718
import { LCContext, queryPage } from '../utility';
@@ -46,18 +47,20 @@ export class LogisticsController {
4647

4748
logistics = await new Logistics()
4849
.setACL(acl)
49-
.save({ ...rest, name, creator: user }, { user });
50+
.save({ ...rest, name, creator: user, verified: false }, { user });
5051

5152
return logistics.toJSON();
5253
}
5354

5455
@Get()
5556
getList(
57+
@QueryParam('verified') verified: boolean,
5658
@QueryParam('pageSize') size: number,
5759
@QueryParam('pageIndex') index: number
5860
) {
5961
return queryPage(Logistics, {
60-
include: ['creator'],
62+
include: ['creator', 'verifier'],
63+
equal: { verified },
6164
size,
6265
index
6366
});
@@ -79,13 +82,32 @@ export class LogisticsController {
7982
) {
8083
let logistics = LCObject.createWithoutData('Logistics', id);
8184

82-
await logistics.save(rest, { user });
85+
await logistics.save(
86+
{ ...rest, verified: false, verifier: null },
87+
{ user }
88+
);
8389

8490
logistics = await new Query(Logistics).include('creator').get(id);
8591

8692
return logistics.toJSON();
8793
}
8894

95+
@Patch('/:id')
96+
@Authorized()
97+
@OnUndefined(204)
98+
async verify(
99+
@Ctx() { currentUser: user }: LCContext,
100+
@Param('id') id: string,
101+
@Body() { verified }: { verified: boolean }
102+
) {
103+
if (!(await RoleController.isAdmin(user))) throw new ForbiddenError();
104+
105+
await LCObject.createWithoutData('Logistics', id).save(
106+
{ verified, verifier: user },
107+
{ user }
108+
);
109+
}
110+
89111
@Delete('/:id')
90112
@Authorized()
91113
@OnUndefined(204)

0 commit comments

Comments
 (0)