24 lines
630 B
TypeScript
24 lines
630 B
TypeScript
import { LessThanOrEqual } from "typeorm";
|
|
import type { HasIdCardVersion } from "external/db/utils/has-id-card-version";
|
|
import type { integer } from "types/misc";
|
|
|
|
export function GetByCardIdAndVersion<T extends HasIdCardVersion>(
|
|
record: typeof HasIdCardVersion & (new (...args: Array<unknown>) => T),
|
|
cardId: integer,
|
|
version: integer
|
|
): Promise<T | null> {
|
|
return record.findOne<T>({
|
|
// @ts-expect-error urgh i hate typescript
|
|
where: {
|
|
card: {
|
|
id: cardId,
|
|
},
|
|
version: LessThanOrEqual(version),
|
|
},
|
|
// @ts-expect-error i've tried a billion ways at this point
|
|
order: {
|
|
version: "desc",
|
|
},
|
|
});
|
|
}
|