Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/dev' into contribute/abbiefarr…
Browse files Browse the repository at this point in the history
…-fetch-unit-summary
  • Loading branch information
abbiefarr committed Aug 13, 2021
2 parents 41c23e8 + 77bfa7b commit 7e7cd69
Show file tree
Hide file tree
Showing 16 changed files with 97 additions and 78 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ All notable changes to this project will be documented in this file. The format
- Fixed:
- Added checks for property in listing.dto transforms
- Display all listings on partners with `limit=all` ([#1635](https://github.com/bloom-housing/bloom/issues/1635)) (Marcin Jędras)
- Seed data should create unique application methods ([#1662](https://github.com/bloom-housing/bloom/issues/1662)) (Emily Jablonski)

## v1.0.5 08/03/2021

Expand Down
1 change: 1 addition & 0 deletions backend/core/archer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ export const ArcherListing: Listing = {
householdSizeMax: 3,
smokingPolicy: "Non-smoking building",
unitsAvailable: 0,
unitsSummary: [],
unitsSummarized: undefined,
unitAmenities: "Dishwasher",
developer: "Charities Housing ",
Expand Down
5 changes: 5 additions & 0 deletions backend/core/scripts/listings-importer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ const authService = new client.AuthService()
const amiChartService = new client.AmiChartsService()
const unitTypesService = new client.UnitTypesService()
const unitAccessibilityPriorityTypesService = new client.UnitAccessibilityPriorityTypesService()
const applicationMethodsService = new client.ApplicationMethodsService()
const reservedCommunityTypesService = new client.ReservedCommunityTypesService()

async function uploadEntity(entityKey, entityService, listing) {
const newRecordsIds = await Promise.all(
Expand Down Expand Up @@ -144,11 +146,14 @@ async function main() {
})
const unitTypes = await unitTypesService.list()
const priorityTypes = await unitAccessibilityPriorityTypesService.list()
const reservedCommunityTypes = await reservedCommunityTypesService.list()

let listing = JSON.parse(fs.readFileSync(listingFilePath, "utf-8"))
const relationsKeys = []
listing = reformatListing(listing, relationsKeys)
listing = await uploadEntity("preferences", preferencesService, listing)
listing = await uploadEntity("applicationMethods", applicationMethodsService, listing)
listing.reservedCommunityType = findByName(reservedCommunityTypes, listing.reservedCommunityType)

const amiChartName = listing.amiChart.name
let chart = await getAmiChart(amiChartName)
Expand Down
2 changes: 0 additions & 2 deletions backend/core/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ export function applicationSetup(app: INestApplication) {
app.useGlobalInterceptors(
new ClassSerializerInterceptor(app.get(Reflector), { excludeExtraneousValues: true })
)
// Starts listening for shutdown hooks
app.enableShutdownHooks()
return app
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { PaperApplicationDto } from "../../paper-applications/dto/paper-applicat
import { IdDto } from "../../shared/dto/id.dto"

export class ApplicationMethodDto extends OmitType(ApplicationMethod, [
"listing",
"paperApplications",
] as const) {
@Expose()
Expand Down
8 changes: 0 additions & 8 deletions backend/core/src/listings/dto/listing.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import { ApplicationMethodDto } from "../../application-methods/dto/application-
import { ListingReviewOrder } from "../types/listing-review-order-enum"
import { ListingEventType } from "../types/listing-event-type-enum"
import { ListingEventCreateDto, ListingEventDto, ListingEventUpdateDto } from "./listing-event.dto"
import { UnitsSummaryDto } from "../../units-summary/dto/units-summary.dto"

export class ListingDto extends OmitType(Listing, [
"applicationAddress",
Expand Down Expand Up @@ -322,13 +321,6 @@ export class ListingDto extends OmitType(Listing, [
)
yearBuilt?: number | null

@Expose()
@IsOptional({ groups: [ValidationsGroupsEnum.default] })
@ValidateNested({ groups: [ValidationsGroupsEnum.default], each: true })
@Type(() => UnitsSummaryDto)
unitsSummary?: UnitsSummaryDto[] | null

// TO BE DEPRECATED
@Expose()
@IsDefined({ groups: [ValidationsGroupsEnum.default] })
@ValidateNested({ groups: [ValidationsGroupsEnum.default] })
Expand Down
4 changes: 2 additions & 2 deletions backend/core/src/listings/entities/listing.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,14 +460,14 @@ class Listing extends BaseEntity {
waitlistOpenSpots?: number | null

@OneToMany(() => UnitsSummary, (summary) => summary.listing, {
nullable: false,
eager: true,
nullable: true,
cascade: true,
})
@Expose()
@ValidateNested({ groups: [ValidationsGroupsEnum.default], each: true })
@Type(() => UnitsSummary)
unitsSummary?: UnitsSummary[] | null
unitsSummary: UnitsSummary[]
}

export { Listing as default, Listing }
23 changes: 15 additions & 8 deletions backend/core/src/listings/listings.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,23 @@ interface RedisStore extends Store {
isCacheableValue: (value: unknown) => boolean
}

const cacheConfig = {
ttl: 24 * 60 * 60,
store: redisStore,
url: process.env.REDIS_URL,
tls: undefined,
}

if (process.env.REDIS_USE_TLS !== "0") {
cacheConfig.url = process.env.REDIS_TLS_URL
cacheConfig.tls = {
rejectUnauthorized: false,
}
}

@Module({
imports: [
CacheModule.register({
ttl: 24 * 60 * 60,
store: redisStore,
url: process.env.REDIS_USE_TLS === "0" ? process.env.REDIS_URL : process.env.REDIS_TLS_URL,
tls: {
rejectUnauthorized: false,
},
}),
CacheModule.register(cacheConfig),
TypeOrmModule.forFeature([Listing, Preference, Unit, User, Property]),
AuthModule,
],
Expand Down
2 changes: 1 addition & 1 deletion backend/core/src/listings/listings.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export class ListingsService {
.leftJoinAndSelect("units.amiChart", "amiChart")
.leftJoinAndSelect("listings.jurisdiction", "jurisdiction")
.leftJoinAndSelect("listings.reservedCommunityType", "reservedCommunityType")
.leftJoinAndSelect("listings.unitsSummary", "unitsSummary")
}

public async list(origin: string, params: ListingsQueryParams): Promise<Pagination<Listing>> {
Expand All @@ -56,7 +57,6 @@ export class ListingsService {
.createQueryBuilder("listings")
.select("listings.id", "listings_id")
.leftJoin("listings.property", "property")
.leftJoin("listings.units_summary", "units_summary")
.groupBy("listings.id")
.orderBy({ "listings.id": "DESC" })

Expand Down
2 changes: 2 additions & 0 deletions backend/core/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import dbOptions = require("../ormconfig")
let app
async function bootstrap() {
app = await NestFactory.create(AppModule.register(dbOptions))
// Starts listening for shutdown hooks
app.enableShutdownHooks()
app = applicationSetup(app)
const conn = getConnection()
// showMigrations returns true if there are pending migrations
Expand Down
53 changes: 14 additions & 39 deletions backend/core/src/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ import { ListingTritonSeed } from "./seeds/listings/listing-triton-seed"
import { ListingDefaultBmrChartSeed } from "./seeds/listings/listing-default-bmr-chart-seed"
import { ApplicationMethodsService } from "./application-methods/application-methods.service"
import { ApplicationMethodType } from "./application-methods/types/application-method-type-enum"
import { PaperApplicationsService } from "./paper-applications/paper-applications.service"
import { Language } from "./shared/types/language-enum"
import { AssetsService } from "./assets/services/assets.service"
import { AuthContext } from "./auth/types/auth-context"
import { ListingDefaultReservedSeed } from "./seeds/listings/listing-default-reserved-seed"
import { ListingDefaultFCFSSeed } from "./seeds/listings/listing-default-fcfs-seed"
Expand Down Expand Up @@ -64,52 +61,29 @@ export async function createLeasingAgents(app: INestApplicationContext) {
return leasingAgents
}

async function createApplicationMethods(app: INestApplicationContext) {
const assetsService = await app.resolve<AssetsService>(AssetsService)
const englishFileAsset = await assetsService.create({
fileId: "englishFileId",
label: "English paper application",
})
const paperApplicationsService = await app.resolve<PaperApplicationsService>(
PaperApplicationsService
)
const englishPaperApplication = await paperApplicationsService.create({
language: Language.en,
file: englishFileAsset,
})
const applicationMethodsService = await app.resolve<ApplicationMethodsService>(
ApplicationMethodsService
)

await applicationMethodsService.create({
type: ApplicationMethodType.FileDownload,
acceptsPostmarkedApplications: false,
externalReference: "https://bit.ly/2wH6dLF",
label: "English",
paperApplications: [englishPaperApplication],
})

await applicationMethodsService.create({
type: ApplicationMethodType.Internal,
acceptsPostmarkedApplications: false,
externalReference: "",
label: "Label",
paperApplications: [],
})
}

const seedListings = async (app: INestApplicationContext) => {
const seeds = []
const leasingAgents = await createLeasingAgents(app)
await createApplicationMethods(app)

const allSeeds = listingSeeds.map((listingSeed) => app.get<ListingDefaultSeed>(listingSeed))
const listingRepository = app.get<Repository<Listing>>(getRepositoryToken(Listing))
const applicationMethodsService = await app.resolve<ApplicationMethodsService>(
ApplicationMethodsService
)

for (const [index, listingSeed] of allSeeds.entries()) {
const everyOtherAgent = index % 2 ? leasingAgents[0] : leasingAgents[1]
const listing = await listingSeed.seed()
listing.leasingAgents = [everyOtherAgent]
const applicationMethods = await applicationMethodsService.create({
type: ApplicationMethodType.Internal,
acceptsPostmarkedApplications: false,
externalReference: "",
label: "Label",
paperApplications: [],
listing: listing,
})
listing.applicationMethods = [applicationMethods]
await listingRepository.save(listing)

seeds.push(listing)
Expand All @@ -120,7 +94,8 @@ const seedListings = async (app: INestApplicationContext) => {

async function seed() {
const app = await NestFactory.create(SeederModule.forRoot({ test: argv.test }))

// Starts listening for shutdown hooks
app.enableShutdownHooks()
const userService = await app.resolve<UserService>(UserService)

const userRepo = app.get<Repository<User>>(getRepositoryToken(User))
Expand Down
5 changes: 0 additions & 5 deletions backend/core/src/seeds/listings/listing-coliseum-seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { Listing } from "../../listings/entities/listing.entity"
import { BaseEntity, DeepPartial } from "typeorm"
import { UnitCreateDto } from "../../units/dto/unit.dto"
import { ListingDefaultSeed } from "./listing-default-seed"
import { ApplicationMethodType } from "../../application-methods/types/application-method-type-enum"
import { UnitStatus } from "../../units/types/unit-status-enum"

const coliseumProperty: PropertySeedType = {
Expand Down Expand Up @@ -1011,9 +1010,6 @@ export class ListingColiseumSeed extends ListingDefaultSeed {
}

await this.unitsRepository.save(unitsToBeCreated)
const applicationMethods = await this.applicationMethodRepository.find({
type: ApplicationMethodType.Internal,
})

const listingCreateDto: Omit<
DeepPartial<Listing>,
Expand All @@ -1027,7 +1023,6 @@ export class ListingColiseumSeed extends ListingDefaultSeed {
{ ...getPbvPreference(), ordinal: 2, page: 2 },
{ ...getHopwaPreference(), ordinal: 3, page: 3 },
],
applicationMethods: applicationMethods,
events: [],
}

Expand Down
6 changes: 0 additions & 6 deletions backend/core/src/seeds/listings/listing-default-seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
getLiveWorkPreference,
} from "./shared"
import { ApplicationMethod } from "../../application-methods/entities/application-method.entity"
import { ApplicationMethodType } from "../../application-methods/types/application-method-type-enum"

export class ListingDefaultSeed {
constructor(
Expand Down Expand Up @@ -69,11 +68,7 @@ export class ListingDefaultSeed {
unitsToBeCreated[1].priorityType = priorityTypeMobilityAndHearing
unitsToBeCreated[0].unitType = unitTypeOneBdrm
unitsToBeCreated[1].unitType = unitTypeTwoBdrm

await this.unitsRepository.save(unitsToBeCreated)
const applicationMethods = await this.applicationMethodRepository.find({
type: ApplicationMethodType.Internal,
})

const listingCreateDto: Omit<
DeepPartial<Listing>,
Expand All @@ -84,7 +79,6 @@ export class ListingDefaultSeed {
property: property,
assets: getDefaultAssets(),
preferences: [getLiveWorkPreference(), { ...getDisplaceePreference(), ordinal: 2 }],
applicationMethods: applicationMethods,
events: getDefaultListingEvents(),
}

Expand Down
5 changes: 0 additions & 5 deletions backend/core/src/seeds/listings/listing-triton-seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { getDefaultAmiChart, getDate, getDefaultAssets, getLiveWorkPreference }
import { ListingStatus } from "../../listings/types/listing-status-enum"
import { CountyCode } from "../../shared/types/county-code"
import { CSVFormattingType } from "../../csv/types/csv-formatting-type-enum"
import { ApplicationMethodType } from "../../application-methods/types/application-method-type-enum"
import { AmiChart } from "../../ami-charts/entities/ami-chart.entity"
import { ListingDefaultSeed } from "./listing-default-seed"
import { UnitCreateDto } from "../../units/dto/unit.dto"
Expand Down Expand Up @@ -782,9 +781,6 @@ export class ListingTritonSeed extends ListingDefaultSeed {
unitsToBeCreated[4].unitType = unitTypeOneBdrm

await this.unitsRepository.save(unitsToBeCreated)
const applicationMethods = await this.applicationMethodRepository.find({
type: ApplicationMethodType.FileDownload,
})

const listingCreateDto: Omit<
DeepPartial<Listing>,
Expand All @@ -794,7 +790,6 @@ export class ListingTritonSeed extends ListingDefaultSeed {
property: property,
assets: getDefaultAssets(),
preferences: [getLiveWorkPreference()],
applicationMethods: applicationMethods,
events: [],
}

Expand Down
4 changes: 3 additions & 1 deletion backend/core/test/listings/listings.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { PaperApplicationsModule } from "../../src/paper-applications/paper-appl
import { ListingEventCreateDto } from "../../src/listings/dto/listing-event.dto"
import { ListingEventType } from "../../src/listings/types/listing-event-type-enum"
import { getSeedListingsCount } from "../../src/seed"
import { Listing } from "../../src/listings/entities/listing.entity"

// eslint-disable-next-line @typescript-eslint/no-var-requires
const dbOptions = require("../../ormconfig.test")
Expand Down Expand Up @@ -152,7 +153,7 @@ describe("Listings", () => {
it("should add/overwrite application methods in existing listing", async () => {
const res = await supertest(app.getHttpServer()).get("/listings").expect(200)

const listing: ListingUpdateDto = { ...res.body.items[0] }
const listing: Listing = { ...res.body.items[0] }

const adminAccessToken = await getUserAccessToken(app, "[email protected]", "abcdef")

Expand All @@ -176,6 +177,7 @@ describe("Listings", () => {
const am: ApplicationMethodCreateDto = {
type: ApplicationMethodType.FileDownload,
paperApplications: [{ id: paperApplication.body.id }],
listing: listing,
}

const applicationMethod = await supertest(app.getHttpServer())
Expand Down
Loading

0 comments on commit 7e7cd69

Please sign in to comment.