Skip to content

Commit 1e6e0ef

Browse files
committed
【新增】物流公司 接口、模型
【优化】医疗物资需求可搜索 【新增】云服务捐助说明
1 parent a15869c commit 1e6e0ef

File tree

6 files changed

+147
-4
lines changed

6 files changed

+147
-4
lines changed

ReadMe.md

+7
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,15 @@ lean up
4949

5050
- 短信验证码:`003754`
5151

52+
## 特别感谢
53+
54+
[freeCodeCamp 成都社区][1]捐助 ¥ 900 用于购买 **LeanCloud 商业版**一个月,以支撑**每日超 3 万次**的 API 访问。
55+
56+
![](document/LeanCloud-account.png)
57+
5258
[1]: https://koajs.com/
5359
[2]: https://www.typescriptlang.org/
5460
[3]: https://leancloud.cn/
5561
[4]: https://david-dm.org/wuhan2020/rest-api
5662
[5]: https://travis-ci.com/wuhan2020/rest-api
63+
[6]: https://fcc-cd.tk/

document/LeanCloud-account.png

31.4 KB
Loading

source/controller/Logistics.ts

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import { Object as LCObject, Query, ACL } from 'leanengine';
2+
import {
3+
JsonController,
4+
Post,
5+
Authorized,
6+
Ctx,
7+
Body,
8+
ForbiddenError,
9+
Get,
10+
QueryParam,
11+
Param,
12+
Put,
13+
Delete,
14+
OnUndefined
15+
} from 'routing-controllers';
16+
17+
import { LCContext, queryPage } from '../utility';
18+
import { LogisticsModel } from '../model/Logistics';
19+
import { RoleController } from './Role';
20+
21+
export class Logistics extends LCObject {}
22+
23+
@JsonController('/logistics')
24+
export class LogisticsController {
25+
@Post()
26+
@Authorized()
27+
async create(
28+
@Ctx() { currentUser: user }: LCContext,
29+
@Body() { name, ...rest }: LogisticsModel
30+
) {
31+
let logistics = await new Query(Logistics)
32+
.equalTo('name', name)
33+
.first();
34+
35+
if (logistics)
36+
throw new ForbiddenError(
37+
'同一物流公司不能重复发布,请联系原发布者修改'
38+
);
39+
40+
const acl = new ACL();
41+
42+
acl.setPublicReadAccess(true),
43+
acl.setPublicWriteAccess(false),
44+
acl.setWriteAccess(user, true),
45+
acl.setRoleWriteAccess(await RoleController.getAdmin(), true);
46+
47+
logistics = await new Logistics()
48+
.setACL(acl)
49+
.save({ ...rest, name, creator: user }, { user });
50+
51+
return logistics.toJSON();
52+
}
53+
54+
@Get()
55+
getList(
56+
@QueryParam('pageSize') size: number,
57+
@QueryParam('pageIndex') index: number
58+
) {
59+
return queryPage(Logistics, {
60+
include: ['creator'],
61+
size,
62+
index
63+
});
64+
}
65+
66+
@Get('/:id')
67+
async getOne(@Param('id') id: string) {
68+
const logistics = await new Query(Logistics).get(id);
69+
70+
return logistics.toJSON();
71+
}
72+
73+
@Put('/:id')
74+
@Authorized()
75+
async edit(
76+
@Ctx() { currentUser: user }: LCContext,
77+
@Param('id') id: string,
78+
@Body() { name, ...rest }: LogisticsModel
79+
) {
80+
let logistics = LCObject.createWithoutData('Logistics', id);
81+
82+
await logistics.save(rest, { user });
83+
84+
logistics = await new Query(Logistics).include('creator').get(id);
85+
86+
return logistics.toJSON();
87+
}
88+
89+
@Delete('/:id')
90+
@Authorized()
91+
@OnUndefined(204)
92+
async delete(
93+
@Ctx() { currentUser: user }: LCContext,
94+
@Param('id') id: string
95+
) {
96+
await LCObject.createWithoutData('Logistics', id).destroy({
97+
user
98+
});
99+
}
100+
}

source/controller/SuppliesRequirement.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,26 @@ export class RequirementController {
4444
acl.setWriteAccess(user, true),
4545
acl.setRoleWriteAccess(await RoleController.getAdmin(), true);
4646

47-
requirement = await new SuppliesRequirement().save(
48-
{ ...rest, hospital, creator: user },
49-
{ user }
50-
);
47+
requirement = await new SuppliesRequirement()
48+
.setACL(acl)
49+
.save({ ...rest, hospital, creator: user }, { user });
5150

5251
return requirement.toJSON();
5352
}
5453

5554
@Get()
5655
getList(
56+
@QueryParam('province') province: string,
57+
@QueryParam('city') city: string,
58+
@QueryParam('district') district: string,
59+
@QueryParam('hospital') hospital: string,
5760
@QueryParam('pageSize') size: number,
5861
@QueryParam('pageIndex') index: number
5962
) {
6063
return queryPage(SuppliesRequirement, {
6164
include: ['creator'],
65+
equal: { province, city, district },
66+
contains: { hospital },
6267
size,
6368
index
6469
});

source/model/Logistics.ts

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { Length, IsUrl, IsArray, IsOptional, IsString } from 'class-validator';
2+
import { Contact } from './Supplies';
3+
4+
export interface ServiceArea {
5+
city: string;
6+
direction: 'in' | 'out' | 'both';
7+
personal: boolean;
8+
}
9+
10+
export class LogisticsModel {
11+
@Length(3)
12+
name: string;
13+
14+
@IsUrl()
15+
url: string;
16+
17+
@IsArray()
18+
contacts: Contact[];
19+
20+
@IsArray()
21+
serviceArea: ServiceArea[];
22+
23+
@IsOptional()
24+
@IsString()
25+
remark?: string;
26+
}

source/utility.ts

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ interface PageQuery {
2121
equal?: Condition;
2222
less?: Condition;
2323
greater?: Condition;
24+
contains?: Condition;
2425
ascend?: string[];
2526
descend?: string[];
2627
select?: string[];
@@ -36,6 +37,7 @@ export async function queryPage<T extends Queriable>(
3637
equal,
3738
less,
3839
greater,
40+
contains,
3941
ascend = [],
4042
descend = ['updatedAt', 'createdAt'],
4143
select = [],
@@ -54,6 +56,9 @@ export async function queryPage<T extends Queriable>(
5456
for (const key in greater)
5557
if (greater[key] != null) query.greaterThanOrEqualTo(key, greater[key]);
5658

59+
for (const key in contains)
60+
if (contains[key] != null) query.contains(key, contains[key]);
61+
5762
const count = await query.count(auth);
5863

5964
if (!count) return { data: [], count };

0 commit comments

Comments
 (0)