File tree Expand file tree Collapse file tree 2 files changed +35
-8
lines changed Expand file tree Collapse file tree 2 files changed +35
-8
lines changed Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ services:
9
9
depends_on :
10
10
- db
11
11
ports :
12
- - " ${PORT}:${PORT}"
12
+ - ' ${PORT}:${PORT}'
13
13
volumes :
14
14
- .:/usr/app
15
15
- /usr/app/node_modules
@@ -30,7 +30,7 @@ services:
30
30
container_name : sos-rs-db
31
31
image : postgres
32
32
ports :
33
- - " ${DB_PORT}:${DB_PORT}"
33
+ - ' ${DB_PORT}:${DB_PORT}'
34
34
environment :
35
35
- POSTGRES_PASSWORD=${DB_PASSWORD}
36
36
- POSTGRES_USER=${DB_USER}
Original file line number Diff line number Diff line change @@ -82,18 +82,45 @@ export class ShelterSupplyService {
82
82
async updateMany ( body : z . infer < typeof UpdateManyShelterSupplySchema > ) {
83
83
const { ids, shelterId } = UpdateManyShelterSupplySchema . parse ( body ) ;
84
84
85
- await this . prismaService . shelterSupply . updateMany ( {
85
+ const supplies = await this . prismaService . shelterSupply . findMany ( {
86
86
where : {
87
- shelterId : shelterId ,
87
+ shelterId,
88
88
supplyId : {
89
89
in : ids ,
90
90
} ,
91
91
} ,
92
- data : {
93
- priority : SupplyPriority . UnderControl ,
94
- updatedAt : new Date ( ) . toISOString ( ) ,
95
- } ,
96
92
} ) ;
93
+
94
+ const prioritySum = supplies . reduce (
95
+ ( prev , current ) => prev + current . priority ,
96
+ 0 ,
97
+ ) ;
98
+
99
+ await this . prismaService . $transaction ( [
100
+ this . prismaService . shelter . update ( {
101
+ where : {
102
+ id : shelterId ,
103
+ } ,
104
+ data : {
105
+ prioritySum : {
106
+ decrement : prioritySum ,
107
+ } ,
108
+ updatedAt : new Date ( ) . toISOString ( ) ,
109
+ } ,
110
+ } ) ,
111
+ this . prismaService . shelterSupply . updateMany ( {
112
+ where : {
113
+ shelterId,
114
+ supplyId : {
115
+ in : ids ,
116
+ } ,
117
+ } ,
118
+ data : {
119
+ priority : SupplyPriority . UnderControl ,
120
+ updatedAt : new Date ( ) . toISOString ( ) ,
121
+ } ,
122
+ } ) ,
123
+ ] ) ;
97
124
}
98
125
99
126
async index ( shelterId : string ) {
You can’t perform that action at this time.
0 commit comments