Bugfixes
This commit is contained in:
@@ -68,7 +68,13 @@ export class ListingsService {
|
||||
.where(sql`${table.id} = ${id}`);
|
||||
return result[0] as BusinessListing | CommercialPropertyListing;
|
||||
}
|
||||
|
||||
async findByImagePath(imagePath: string): Promise<CommercialPropertyListing> {
|
||||
const result = await this.conn
|
||||
.select()
|
||||
.from(commercials)
|
||||
.where(sql`${commercials.imagePath} = ${imagePath}`);
|
||||
return result[0] as CommercialPropertyListing;
|
||||
}
|
||||
async findByUserId(userId: string, table: typeof businesses | typeof commercials): Promise<BusinessListing[] | CommercialPropertyListing[]> {
|
||||
return (await this.conn.select().from(table).where(eq(table.userId, userId))) as BusinessListing[] | CommercialPropertyListing[];
|
||||
}
|
||||
@@ -76,8 +82,6 @@ export class ListingsService {
|
||||
async createListing(data: BusinessListing | CommercialPropertyListing, table: typeof businesses | typeof commercials): Promise<BusinessListing | CommercialPropertyListing> {
|
||||
data.created = new Date();
|
||||
data.updated = new Date();
|
||||
data.visits = 0;
|
||||
data.lastVisit = null;
|
||||
const [createdListing] = await this.conn.insert(table).values(data).returning();
|
||||
return createdListing as BusinessListing | CommercialPropertyListing;
|
||||
}
|
||||
@@ -116,10 +120,9 @@ export class ListingsService {
|
||||
await this.updateListing(listing.id, listing, commercials);
|
||||
}
|
||||
}
|
||||
async addImage(id: string, imagename: string) {
|
||||
const listing = (await this.findById(id, commercials)) as unknown as CommercialPropertyListing;
|
||||
async addImage(imagePath: string, imagename: string) {
|
||||
const listing = (await this.findByImagePath(imagePath)) as unknown as CommercialPropertyListing;
|
||||
listing.imageOrder.push(imagename);
|
||||
listing.imagePath = listing.id;
|
||||
await this.updateListing(listing.id, listing, commercials);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user