serialID added
This commit is contained in:
parent
93ff8c3378
commit
8624c1b8da
|
|
@ -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 };
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue