More fixes

This commit is contained in:
2024-06-25 18:27:53 -05:00
parent 3cdf3b54ed
commit e1f8c15e9a
10 changed files with 454 additions and 239 deletions
+51 -48
View File
@@ -22,7 +22,17 @@ enum BusinessType {
other,
}
enum JobType { cashier, server, mechanic, other }
enum JobType {
retail,
customerService,
foodService,
finance,
healthcare,
education,
maintenance,
manufacturing,
other,
}
enum OfferType { job, internship, apprenticeship }
@@ -177,53 +187,46 @@ void main() async {
OfferType.values.asNameMap().keys;
var postgresResult = (await postgres.query('''
WITH business_listings AS (
SELECT b.id AS business_id,
b.name AS business_name,
b."contactName" AS business_contactName,
b."contactEmail" AS business_contactEmail,
b."contactPhone" AS business_contactPhone,
b."locationName" AS business_locationName,
b."locationAddress" AS business_locationAddress,
l.type AS listing_type,
json_agg(
json_build_object(
'id', l.id,
'businessId', l."businessId",
'name', l.name,
'description', l.description,
'type', l.type,
'offerType', l."offerType",
'wage', l.wage,
'link', l.link
)
) AS listings
FROM businesses b
JOIN listings l ON b.id = l."businessId"
WHERE l.type IN (${typeFilters.map((element) => "'$element'").join(',')})
AND l."offerType" IN (${offerFilters.map((element) => "'$element'").join(',')})
GROUP BY b.id, b.name, b."contactName", b."contactEmail", b."contactPhone",
b."locationName", b."locationAddress", l.type
),
aggregated_businesses AS (
SELECT listing_type,
json_agg(
json_build_object(
'id', business_id,
'name', business_name,
'contactName', business_contactName,
'contactEmail', business_contactEmail,
'contactPhone', business_contactPhone,
'locationName', business_locationName,
'locationAddress', business_locationAddress,
'listings', listings
)
) AS businesses
FROM business_listings
GROUP BY listing_type
)
SELECT jsonb_object_agg(listing_type, businesses) AS result
FROM aggregated_businesses;
SELECT jsonb_agg(
jsonb_build_object(
'id', b.id,
'name', b.name,
'contactName', b."contactName",
'contactEmail', b."contactEmail",
'contactPhone', b."contactPhone",
'locationName', b."locationName",
'locationAddress', b."locationAddress",
'listings', b.listings
)
) AS result
FROM (
SELECT
businesses.id,
businesses.name,
businesses."contactName",
businesses."contactEmail",
businesses."contactPhone",
businesses."locationName",
businesses."locationAddress",
jsonb_agg(
jsonb_build_object(
'id', listings.id,
'name', listings.name,
'description', listings.description,
'type', listings.type,
'wage', listings.wage,
'link', listings.link,
'offerType', listings."offerType"
)
) AS listings
FROM businesses
JOIN listings ON businesses.id = listings."businessId"
AND listings.type IN (${typeFilters.map((element) => "'$element'").join(',')})
AND listings."offerType" IN (${offerFilters.map((element) => "'$element'").join(',')})
GROUP BY businesses.id, businesses.name, businesses."contactName", businesses."contactEmail",
businesses."contactPhone", businesses."locationName", businesses."locationAddress"
) b
WHERE b.listings IS NOT NULL;
'''));
return Response.ok(