Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions apps/web-app/server/api/kitchen/revenue/iiko-daily.post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ async function parseFileAndUpdateData(file: MultiPartData) {
// Update common data
const commonAverageCheck = Math.round(parsedKitchens.reduce((acc, curr) => acc + curr.averageCheck, 0) / parsedKitchens.length)
const commonTotal = Math.round(parsedKitchens.reduce((acc, curr) => acc + curr.total, 0) / parsedKitchens.length)
const checks = Math.round(parsedKitchens.reduce((acc, curr) => acc + curr.checks, 0))
const total = Math.round(parsedKitchens.reduce((acc, curr) => acc + curr.total, 0))

for (const kitchen of parsedKitchens) {
kitchen.commonAverageCheck = commonAverageCheck
Expand All @@ -159,13 +161,17 @@ async function parseFileAndUpdateData(file: MultiPartData) {
if (!existingMetrics) {
await repository.network.createMetrics({
date: dateOnly,
checks,
total,
averageCheck: commonAverageCheck,
total: commonTotal,
averageTotal: commonTotal,
})
} else {
await repository.network.updateMetrics(existingMetrics.id, {
checks,
total,
averageCheck: commonAverageCheck,
total: commonTotal,
averageTotal: commonTotal,
})
}

Expand Down
2 changes: 2 additions & 0 deletions packages/database/src/tables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,8 @@ export const networkMetrics = pgTable('network_metrics', {
updatedAt: timestamp('updated_at', { precision: 3, withTimezone: true, mode: 'string' }).notNull().defaultNow(),
date: date('date', { mode: 'string' }).notNull(),
total: numeric('total', { mode: 'number' }).notNull().default(0),
averageTotal: numeric('average_total', { mode: 'number' }).notNull().default(0),
checks: integer('checks').notNull().default(0),
averageCheck: numeric('average_check', { mode: 'number' }).notNull().default(0),
})

Expand Down