serialID added

This commit is contained in:
Andreas Knuth 2025-08-05 18:20:55 -05:00
parent 93ff8c3378
commit 8624c1b8da
1 changed files with 14 additions and 0 deletions

View File

@ -162,8 +162,22 @@ export class CommercialPropertyService {
// #### CREATE ######################################## // #### CREATE ########################################
async createListing(data: CommercialPropertyListing): Promise<CommercialPropertyListing> { async createListing(data: CommercialPropertyListing): Promise<CommercialPropertyListing> {
try { try {
// Hole die nächste serialId von der Sequence
const sequenceResult = await this.conn.execute(sql`SELECT nextval('commercials_json_serial_id_seq') AS serialid`);
// Prüfe, ob ein gültiger Wert zurückgegeben wurde
if (!sequenceResult.rows || !sequenceResult.rows[0] || sequenceResult.rows[0].serialid === undefined) {
throw new Error('Failed to retrieve serialId from sequence commercials_json_serial_id_seq');
}
const serialId = Number(sequenceResult.rows[0].serialid); // Konvertiere BIGINT zu Number
if (isNaN(serialId)) {
throw new Error('Invalid serialId received from sequence');
}
data.created = data.created ? (typeof data.created === 'string' ? new Date(data.created) : data.created) : new Date(); data.created = data.created ? (typeof data.created === 'string' ? new Date(data.created) : data.created) : new Date();
data.updated = new Date(); data.updated = new Date();
data.serialId = Number(serialId);
CommercialPropertyListingSchema.parse(data); CommercialPropertyListingSchema.parse(data);
const { id, email, ...rest } = data; const { id, email, ...rest } = data;
const convertedCommercialPropertyListing = { email, data: rest }; const convertedCommercialPropertyListing = { email, data: rest };