Skip to content

Commit

Permalink
Fix #493 - Allow setting individual scope2 values to null to get …
Browse files Browse the repository at this point in the history
…correct calculations of total emissions (#494)
  • Loading branch information
Greenheart authored Dec 16, 2024
1 parent 75e29b9 commit c3518b0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/lib/prisma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ export async function upsertScope1(

export async function upsertScope2(
emissions: Emissions,
scope2: OptionalNullable<Omit<Scope2, 'id' | 'metadataId' | 'unit'>> | null,
scope2: {
lb?: number | null
mb?: number | null
unknown?: number | null
} | null,
metadata: Metadata
) {
if (scope2 === null) {
Expand Down
12 changes: 9 additions & 3 deletions src/routes/updateCompanies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,13 +329,19 @@ export const emissionsSchema = z
.object({
mb: z
.number({ description: 'Market-based scope 2 emissions' })
.optional(),
.optional()
.nullable()
.describe('Sending null means deleting mb scope 2 emissions'),
lb: z
.number({ description: 'Location-based scope 2 emissions' })
.optional(),
.optional()
.nullable()
.describe('Sending null means deleting lb scope 2 emissions'),
unknown: z
.number({ description: 'Unspecified Scope 2 emissions' })
.optional(),
.optional()
.nullable()
.describe('Sending null means deleting unknown scope 2 emissions'),
})
.refine(
({ mb, lb, unknown }) =>
Expand Down

0 comments on commit c3518b0

Please sign in to comment.