-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: update seeds + fix listing delete (#3940)
- Loading branch information
1 parent
567381f
commit 18df523
Showing
8 changed files
with
197 additions
and
22 deletions.
There are no files selected for viewing
110 changes: 110 additions & 0 deletions
110
api/prisma/migrations/08_updating_on_delete_cascades_listings_and_applications/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
-- DropForeignKey | ||
|
||
ALTER TABLE "application_methods" | ||
DROP CONSTRAINT "application_methods_listing_id_fkey"; | ||
|
||
-- AddForeignKey | ||
|
||
ALTER TABLE "application_methods" ADD CONSTRAINT "application_methods_listing_id_fkey" | ||
FOREIGN KEY ("listing_id") REFERENCES "listings"("id") ON | ||
DELETE CASCADE ON | ||
UPDATE NO ACTION; | ||
|
||
-- DropForeignKey | ||
|
||
ALTER TABLE "applications" | ||
DROP CONSTRAINT "applications_listing_id_fkey"; | ||
|
||
-- AddForeignKey | ||
|
||
ALTER TABLE "applications" ADD CONSTRAINT "applications_listing_id_fkey" | ||
FOREIGN KEY ("listing_id") REFERENCES "listings"("id") ON | ||
DELETE | ||
SET NULL ON | ||
UPDATE NO ACTION; | ||
|
||
-- DropForeignKey | ||
|
||
ALTER TABLE "listing_images" | ||
DROP CONSTRAINT "listing_images_listing_id_fkey"; | ||
|
||
-- AddForeignKey | ||
|
||
ALTER TABLE "listing_images" ADD CONSTRAINT "listing_images_listing_id_fkey" | ||
FOREIGN KEY ("listing_id") REFERENCES "listings"("id") ON | ||
DELETE CASCADE ON | ||
UPDATE NO ACTION; | ||
|
||
-- DropForeignKey | ||
|
||
ALTER TABLE "listing_events" | ||
DROP CONSTRAINT "listing_events_listing_id_fkey"; | ||
|
||
-- AddForeignKey | ||
|
||
ALTER TABLE "listing_events" ADD CONSTRAINT "listing_events_listing_id_fkey" | ||
FOREIGN KEY ("listing_id") REFERENCES "listings"("id") ON | ||
DELETE CASCADE ON | ||
UPDATE NO ACTION; | ||
|
||
-- DropForeignKey | ||
|
||
ALTER TABLE "listing_multiselect_questions" | ||
DROP CONSTRAINT "listing_multiselect_questions_listing_id_fkey"; | ||
|
||
-- AddForeignKey | ||
|
||
ALTER TABLE "listing_multiselect_questions" ADD CONSTRAINT "listing_multiselect_questions_listing_id_fkey" | ||
FOREIGN KEY ("listing_id") REFERENCES "listings"("id") ON | ||
DELETE CASCADE ON | ||
UPDATE NO ACTION; | ||
|
||
-- DropForeignKey | ||
|
||
ALTER TABLE "units_summary" | ||
DROP CONSTRAINT "units_summary_listing_id_fkey"; | ||
|
||
-- AddForeignKey | ||
|
||
ALTER TABLE "units_summary" ADD CONSTRAINT "units_summary_listing_id_fkey" | ||
FOREIGN KEY ("listing_id") REFERENCES "listings"("id") ON | ||
DELETE CASCADE ON | ||
UPDATE NO ACTION; | ||
|
||
-- DropForeignKey | ||
|
||
ALTER TABLE "application_flagged_set" | ||
DROP CONSTRAINT "application_flagged_set_listing_id_fkey"; | ||
|
||
-- AddForeignKey | ||
|
||
ALTER TABLE "application_flagged_set" ADD CONSTRAINT "application_flagged_set_listing_id_fkey" | ||
FOREIGN KEY ("listing_id") REFERENCES "listings"("id") ON | ||
DELETE CASCADE ON | ||
UPDATE NO ACTION; | ||
|
||
-- DropForeignKey | ||
|
||
ALTER TABLE "paper_applications" | ||
DROP CONSTRAINT "paper_applications_application_method_id_fkey"; | ||
|
||
-- AddForeignKey | ||
|
||
ALTER TABLE "paper_applications" ADD CONSTRAINT "paper_applications_application_method_id_fkey" | ||
FOREIGN KEY ("application_method_id") REFERENCES "application_methods"("id") ON | ||
DELETE | ||
SET NULL ON | ||
UPDATE NO ACTION; | ||
|
||
-- DropForeignKey | ||
|
||
ALTER TABLE "household_member" | ||
DROP CONSTRAINT "household_member_application_id_fkey"; | ||
|
||
-- AddForeignKey | ||
|
||
ALTER TABLE "household_member" ADD CONSTRAINT "household_member_application_id_fkey" | ||
FOREIGN KEY ("application_id") REFERENCES "applications"("id") ON | ||
DELETE CASCADE ON | ||
UPDATE NO ACTION; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,12 +4,25 @@ import { | |
MultiselectQuestions, | ||
PrismaClient, | ||
ListingsStatusEnum, | ||
ApplicationMethodsTypeEnum, | ||
} from '@prisma/client'; | ||
import { randomInt } from 'crypto'; | ||
import { randomName } from './word-generator'; | ||
import { addressFactory } from './address-factory'; | ||
import { unitFactoryMany } from './unit-factory'; | ||
import { reservedCommunityTypeFactoryGet } from './reserved-community-type-factory'; | ||
|
||
const cloudinaryIds = [ | ||
'dev/blake-wheeler-zBHU08hdzhY-unsplash_swqash', | ||
'dev/krzysztof-hepner-V7Q0Oh3Az-c-unsplash_xoj7sr', | ||
'dev/dillon-kydd-2keCPb73aQY-unsplash_lm7krp', | ||
'dev/inside_qo9wre', | ||
'dev/interior_mc9erd', | ||
'dev/apartment_ez3yyz', | ||
'dev/trayan-xIOYJSVEZ8c-unsplash_f1axsg', | ||
'dev/apartment_building_2_b7ujdd', | ||
]; | ||
|
||
export const listingFactory = async ( | ||
jurisdictionId: string, | ||
prismaClient: PrismaClient, | ||
|
@@ -25,6 +38,8 @@ export const listingFactory = async ( | |
applications?: Prisma.ApplicationsCreateInput[]; | ||
applicationDueDate?: Date; | ||
afsLastRunSetInPast?: boolean; | ||
digitalApp?: boolean; | ||
noImage?: boolean; | ||
}, | ||
): Promise<Prisma.ListingsCreateInput> => { | ||
const previousListing = optionalParams?.listing || {}; | ||
|
@@ -39,6 +54,11 @@ export const listingFactory = async ( | |
prismaClient, | ||
jurisdictionId, | ||
); | ||
|
||
const digitalApp = !!optionalParams?.digitalApp | ||
? optionalParams.digitalApp | ||
: Math.random() < 0.5; | ||
|
||
return { | ||
createdAt: new Date(), | ||
assets: [], | ||
|
@@ -60,11 +80,14 @@ export const listingFactory = async ( | |
listingsApplicationDropOffAddress: { | ||
create: addressFactory(), | ||
}, | ||
reservedCommunityTypes: { | ||
connect: { | ||
id: reservedCommunityType.id, | ||
}, | ||
}, | ||
reservedCommunityTypes: | ||
Math.random() < 0.5 | ||
? { | ||
connect: { | ||
id: reservedCommunityType.id, | ||
}, | ||
} | ||
: {}, | ||
// For application flagged set tests the date needs to be before the updated timestamp | ||
// All others should be a newer timestamp so that they are not picked up by AFS tests | ||
afsLastRunAt: optionalParams?.afsLastRunSetInPast | ||
|
@@ -93,7 +116,6 @@ export const listingFactory = async ( | |
...featuresAndUtilites(), | ||
...buildingFeatures(optionalParams?.includeBuildingFeatures), | ||
...additionalEligibilityRules(optionalParams?.includeEligibilityRules), | ||
...previousListing, | ||
jurisdictions: { | ||
connect: { | ||
id: jurisdictionId, | ||
|
@@ -105,6 +127,35 @@ export const listingFactory = async ( | |
} | ||
: undefined, | ||
applicationDueDate: optionalParams?.applicationDueDate ?? undefined, | ||
developer: randomName(), | ||
leasingAgentName: randomName(), | ||
leasingAgentEmail: '[email protected]', | ||
leasingAgentPhone: '515-604-0183', | ||
digitalApplication: digitalApp, | ||
commonDigitalApplication: digitalApp, | ||
paperApplication: Math.random() < 0.5, | ||
referralOpportunity: Math.random() < 0.5, | ||
applicationMethods: digitalApp | ||
? { | ||
create: { | ||
type: ApplicationMethodsTypeEnum.Internal, | ||
}, | ||
} | ||
: {}, | ||
listingImages: !optionalParams?.noImage | ||
? { | ||
create: { | ||
ordinal: 0, | ||
assets: { | ||
create: { | ||
label: 'cloudinaryBuilding', | ||
fileId: cloudinaryIds[randomInt(cloudinaryIds.length)], | ||
}, | ||
}, | ||
}, | ||
} | ||
: {}, | ||
...previousListing, | ||
}; | ||
}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters