fix(db): match a stay-linked booking on Postgres in the public stay check

publicStayExists cast reservations.accommodation_id straight to integer,
which Postgres refuses for the stored '14.0', so the calendar feed and the
share links failed for every trip once any booking was linked to a stay.
The correlation now goes through accommodationIdMatches, which compares
through the new dialect helper integerTextEqualsKysely, and the Wallet pass
context uses the same helper instead of its own numeric cast.
This commit is contained in:
Maurice
2026-11-17 11:40:14 +01:00
parent 40f6efbf5b
commit 22973036b5
8 changed files with 90 additions and 24 deletions
@@ -2,6 +2,7 @@ import {
castIntegerKysely,
concatKysely,
currentTimestampKysely,
integerTextEqualsKysely,
nowPlusSecondsKysely,
startsWithIsoDateKysely,
substringKysely,
@@ -230,6 +231,22 @@ describe('kysely-functions (postgres)', () => {
expect(compiled.parameters).toEqual([]);
});
it("SQLFPG-026: integerTextEqualsKysely compares the truncated text with the integer, so '14.0' meets 14", () => {
const compiled = db
.selectFrom('users')
.select('id')
.where((eb) => integerTextEqualsKysely(pg, eb, 'display_name', 'id'))
.compile();
expect(compiled.sql).toBe(
'select "id" from "users" where cast(trunc(cast("display_name" as numeric)) as integer) = "id"',
);
expect(compiled.parameters).toEqual([]);
class FakePlatform extends Platform {}
expect(() =>
integerTextEqualsKysely(new FakePlatform(), expressionBuilder<ProbeDB, 'users'>(), 'username', 'id'),
).toThrow(/no implementation for platform FakePlatform/);
});
it('SQLFPG-023: unixEpochToIsoKysely renders UTC ISO text from epoch milliseconds', () => {
const compiled = db
.selectFrom('users')