@@ -3,6 +3,7 @@ import { Injectable } from '@nestjs/common';
3
3
4
4
import { PrismaService } from '../prisma/prisma.service' ;
5
5
import { CreateShelterSupplySchema , UpdateShelterSupplySchema } from './types' ;
6
+ import { SupplyPriority } from '../supply/types' ;
6
7
7
8
@Injectable ( )
8
9
export class ShelterSupplyService {
@@ -27,22 +28,23 @@ export class ShelterSupplyService {
27
28
}
28
29
29
30
async store ( body : z . infer < typeof CreateShelterSupplySchema > ) {
30
- const { shelterId, priority, supplyId } =
31
+ const { shelterId, priority, supplyId, quantity } =
31
32
CreateShelterSupplySchema . parse ( body ) ;
32
33
await this . handleUpdateShelterSum ( shelterId , 0 , priority ) ;
33
34
await this . prismaService . shelterSupply . create ( {
34
35
data : {
35
36
shelterId,
36
37
priority,
37
38
supplyId,
39
+ quantity : priority !== SupplyPriority . UnderControl ? quantity : null ,
38
40
createdAt : new Date ( ) . toISOString ( ) ,
39
41
} ,
40
42
} ) ;
41
43
}
42
44
43
45
async update ( body : z . infer < typeof UpdateShelterSupplySchema > ) {
44
46
const { data, where } = UpdateShelterSupplySchema . parse ( body ) ;
45
- const { priority } = data ;
47
+ const { priority, quantity } = data ;
46
48
if ( priority !== null && priority !== undefined ) {
47
49
const shelterSupply = await this . prismaService . shelterSupply . findFirst ( {
48
50
where : {
@@ -67,6 +69,7 @@ export class ShelterSupplyService {
67
69
} ,
68
70
data : {
69
71
...data ,
72
+ quantity : priority !== SupplyPriority . UnderControl ? quantity : null ,
70
73
createdAt : new Date ( ) . toISOString ( ) ,
71
74
} ,
72
75
} ) ;
@@ -79,6 +82,7 @@ export class ShelterSupplyService {
79
82
} ,
80
83
select : {
81
84
priority : true ,
85
+ quantity : true ,
82
86
supply : {
83
87
select : {
84
88
id : true ,
0 commit comments