@@ -75,7 +75,7 @@ async function parseFileAndUpdateData(file: MultiPartData) {
7575 } )
7676 }
7777
78- const dictionary = data [ 3 ]
78+ const dictionary = data [ 4 ] // 4th row - empty, 5th - column names
7979 if ( ! dictionary ) {
8080 throw createError ( {
8181 statusCode : 400 ,
@@ -85,7 +85,8 @@ async function parseFileAndUpdateData(file: MultiPartData) {
8585
8686 const indexOfName = dictionary . indexOf ( 'Группа' )
8787 const indexOfTotal = dictionary . indexOf ( 'Сумма со скидкой, р. Всего' )
88- if ( ! dictionary || indexOfName < 0 || indexOfTotal < 0 ) {
88+ const indexOfChecks = dictionary . indexOf ( 'Чеков' )
89+ if ( ! dictionary || indexOfName < 0 || indexOfTotal < 0 || indexOfChecks < 0 ) {
8990 throw createError ( {
9091 statusCode : 400 ,
9192 message : 'Invalid dictionary' ,
@@ -111,28 +112,30 @@ async function parseFileAndUpdateData(file: MultiPartData) {
111112 } )
112113 }
113114
114- // Remove first 4 rows and last row
115- const dataRows = data . slice ( 4 , data . length - 1 )
115+ // Remove first 5 rows and last row
116+ const dataRows = data . slice ( 5 , data . length - 1 )
116117 if ( ! dataRows ) {
117118 throw createError ( {
118119 statusCode : 400 ,
119120 message : 'Invalid data' ,
120121 } )
121122 }
122123
123- const parsedKitchens : { name : string , total : number } [ ] = [ ]
124+ const parsedKitchens : { name : string , total : number , checks : number } [ ] = [ ]
124125
125126 for ( const row of dataRows ) {
126127 const name = row [ indexOfName ]
127128 const total = row [ indexOfTotal ]
129+ const checks = row [ indexOfChecks ]
128130
129- if ( typeof name !== 'string' || typeof total !== 'number' ) {
131+ if ( typeof name !== 'string' || typeof total !== 'number' || typeof checks !== 'number' ) {
130132 continue
131133 }
132134
133135 parsedKitchens . push ( {
134136 name,
135137 total,
138+ checks,
136139 } )
137140 }
138141
@@ -151,10 +154,12 @@ async function parseFileAndUpdateData(file: MultiPartData) {
151154 kitchenId : found . id ,
152155 date : dateOnly ,
153156 total : kitchen . total ,
157+ checks : kitchen . checks ,
154158 } )
155159 } else {
156160 await repository . kitchen . updateRevenue ( revenue . id , {
157161 total : kitchen . total ,
162+ checks : kitchen . checks ,
158163 } )
159164 }
160165
0 commit comments