Skip to content

Commit

Permalink
Fix ID validation in set method of model.ts.
Browse files Browse the repository at this point in the history
Ensure that IDs match correctly even when data types like BigInt, Int, or Float are used in GraphQL schemas. This prevents mismatches and ensures error handling for invalid ID comparisons.
  • Loading branch information
jorgecuesta committed Jan 30, 2025
1 parent af233d6 commit cef46a8
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ export class PlainModel<T extends BaseEntity = BaseEntity> implements IModel<T>
}

async set(id: string, data: T, blockHeight: number, tx?: Transaction): Promise<void> {
if (id !== data.id) {
// NOTE: this is to fix the error when use @dbType('BigInt') or maybe Int, Float as parameters on the graphql schema
const dataId = data.id as unknown as string | bigint | number;
if (typeof dataId !== 'string' && typeof dataId.toString === 'function' && dataId.toString() !== id) {
throw new Error(`Id doesnt match with data ${typeof id} !== ${typeof data.id}`);
} else if (typeof dataId === 'string' && dataId !== id) {
throw new Error(`Id doesnt match with data`);
}

Expand Down

0 comments on commit cef46a8

Please sign in to comment.