Skip to content

Commit

Permalink
Merge pull request bloom-housing#1802 from bloom-housing/1728/notific…
Browse files Browse the repository at this point in the history
…ations
  • Loading branch information
emilyjablonski authored Sep 16, 2021
2 parents d4a17dc + 874e63a commit ef4901d
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ All notable changes to this project will be documented in this file. The format
- Adds UnitAmiChartOverride entity and implements ami chart overriding at Unit level [#1575](https://github.com/bloom-housing/bloom/pull/1575)
- Adds `authz.e2e-spec.ts` test cover for preventing user from voluntarily changing his associated `roles` object [#1575](https://github.com/bloom-housing/bloom/pull/1575)
- Adds Jurisdictions to users, listings and translations. The migration script assigns the first alpha sorted jurisdiction to users, so this piece may need to be changed for Detroit, if they have more than Detroit in their DB. [#1776](https://github.com/bloom-housing/bloom/pull/1776)
- Added the optional jurisdiction setting notificationsSignUpURL, which now appears on the home page if set ([#1802](https://github.com/bloom-housing/bloom/pull/1802)) (Emily Jablonski)

- Changed:

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Column, Entity } from "typeorm"
import { AbstractEntity } from "../../shared/entities/abstract.entity"
import { Expose } from "class-transformer"
import { IsString, MaxLength } from "class-validator"
import { IsString, MaxLength, IsOptional } from "class-validator"
import { ValidationsGroupsEnum } from "../../shared/types/validations-groups-enum"

@Entity({ name: "jurisdictions" })
Expand All @@ -11,4 +11,10 @@ export class Jurisdiction extends AbstractEntity {
@IsString({ groups: [ValidationsGroupsEnum.default] })
@MaxLength(256, { groups: [ValidationsGroupsEnum.default] })
name: string

@Column({ nullable: true, type: "text" })
@Expose()
@IsOptional({ groups: [ValidationsGroupsEnum.default] })
@IsString({ groups: [ValidationsGroupsEnum.default] })
notificationsSignUpURL?: string | null
}
15 changes: 13 additions & 2 deletions backend/core/src/jurisdictions/jurisdictions.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
ValidationPipe,
} from "@nestjs/common"
import { ApiBearerAuth, ApiOperation, ApiTags } from "@nestjs/swagger"
import { DefaultAuthGuard } from "../auth/guards/default.guard"
import { OptionalAuthGuard } from "../auth/guards/optional-auth.guard"
import { AuthzGuard } from "../auth/guards/authz.guard"
import { ResourceType } from "../auth/decorators/resource-type.decorator"
import { mapTo } from "../shared/mapTo"
Expand All @@ -27,7 +27,7 @@ import {
@ApiTags("jurisdictions")
@ApiBearerAuth()
@ResourceType("jurisdiction")
@UseGuards(DefaultAuthGuard, AuthzGuard)
@UseGuards(OptionalAuthGuard, AuthzGuard)
@UsePipes(new ValidationPipe(defaultValidationPipeOptions))
export class JurisdictionsController {
constructor(private readonly jurisdictionsService: JurisdictionsService) {}
Expand Down Expand Up @@ -59,6 +59,17 @@ export class JurisdictionsController {
)
}

@Get(`byName/:jurisdictionName`)
@ApiOperation({ summary: "Get jurisdiction by name", operationId: "retrieveByName" })
async retrieveByName(
@Param("jurisdictionName") jurisdictionName: string
): Promise<JurisdictionDto> {
return mapTo(
JurisdictionDto,
await this.jurisdictionsService.findOne({ where: { name: jurisdictionName } })
)
}

@Delete(`:jurisdictionId`)
@ApiOperation({ summary: "Delete jurisdiction by id", operationId: "delete" })
async delete(@Param("jurisdictionId") jurisdictionId: string): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { MigrationInterface, QueryRunner } from "typeorm"
import { CountyCode } from "../shared/types/county-code"

export class addJurisdictionNotificationSetting1630105131436 implements MigrationInterface {
name = "addJurisdictionNotificationSetting1630105131436"

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "jurisdictions" ADD "notifications_sign_up_url" text`)

await queryRunner.query(
`UPDATE "jurisdictions" SET notifications_sign_up_url = 'https://public.govdelivery.com/accounts/CAALAME/signup/29386' WHERE name = ($1)`,
[CountyCode.alameda]
)
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "jurisdictions" DROP COLUMN "notifications_sign_up_url"`)
}
}
27 changes: 26 additions & 1 deletion backend/core/test/jurisdictions/jurisdictions.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ describe("Jurisdictions", () => {

const getById = await supertest(app.getHttpServer())
.get(`/jurisdictions/${res.body.id}`)
.set(...setAuthorization(adminAccesstoken))
.expect(200)
expect(getById.body.name).toBe("test")
})
Expand All @@ -71,4 +70,30 @@ describe("Jurisdictions", () => {
afterAll(async () => {
await app.close()
})

it(`should create and return a new jurisdiction by name`, async () => {
const res = await supertest(app.getHttpServer())
.post(`/jurisdictions`)
.set(...setAuthorization(adminAccesstoken))
.send({ name: "test2" })
.expect(201)
expect(res.body).toHaveProperty("id")
expect(res.body).toHaveProperty("createdAt")
expect(res.body).toHaveProperty("updatedAt")
expect(res.body).toHaveProperty("name")
expect(res.body.name).toBe("test2")

const getByName = await supertest(app.getHttpServer())
.get(`/jurisdictions/byName/${res.body.name}`)
.expect(200)
expect(getByName.body.name).toBe("test2")
})

afterEach(() => {
jest.clearAllMocks()
})

afterAll(async () => {
await app.close()
})
})
9 changes: 9 additions & 0 deletions backend/core/types/src/backend-swagger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3562,6 +3562,9 @@ export interface Jurisdiction {

/** */
name: string

/** */
notificationsSignUpURL?: string
}

export interface User {
Expand Down Expand Up @@ -3821,6 +3824,9 @@ export interface UserInvite {
export interface JurisdictionCreate {
/** */
name: string

/** */
notificationsSignUpURL?: string
}

export interface JurisdictionUpdate {
Expand All @@ -3835,6 +3841,9 @@ export interface JurisdictionUpdate {

/** */
name: string

/** */
notificationsSignUpURL?: string
}

export interface ListingFilterParams {
Expand Down
48 changes: 35 additions & 13 deletions sites/public/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import React, { useState } from "react"
import qs from "qs"
import Head from "next/head"
import { Listing } from "@bloom-housing/backend-core/types"
import { Jurisdiction, Listing } from "@bloom-housing/backend-core/types"
import {
AlertBox,
LinkButton,
Hero,
MarkdownSection,
t,
SiteAlert,
openDateState,
ActionBlock,
Icon,
} from "@bloom-housing/ui-components"
import Layout from "../layouts/application"
import axios from "axios"
Expand All @@ -19,6 +20,7 @@ import moment from "moment"

interface IndexProps {
listings: Listing[]
jurisdiction: Jurisdiction
}

export default function Home(props: IndexProps) {
Expand Down Expand Up @@ -70,14 +72,26 @@ export default function Home(props: IndexProps) {
}
/>
<div className="homepage-extra">
<MarkdownSection fullwidth={true}>
<>
<p>{t("welcome.seeMoreOpportunities")}</p>
<LinkButton href="/additional-resources">
{props.jurisdiction && props.jurisdiction.notificationsSignUpURL && (
<ActionBlock
header={t("welcome.signUp")}
icon={<Icon size="3xl" symbol="mail" />}
actions={[
<LinkButton key={"sign-up"} href={props.jurisdiction.notificationsSignUpURL}>
{t("welcome.signUpToday")}
</LinkButton>,
]}
/>
)}
<ActionBlock
header={t("welcome.seeMoreOpportunities")}
icon={<Icon size="3xl" symbol="building" />}
actions={[
<LinkButton href="/additional-resources" key={"additional-resources"}>
{t("welcome.viewAdditionalHousing")}
</LinkButton>
</>
</MarkdownSection>
</LinkButton>,
]}
/>
</div>
<ConfirmationModal
setSiteAlertMessage={(alertMessage, alertType) => setAlertInfo({ alertMessage, alertType })}
Expand All @@ -88,8 +102,9 @@ export default function Home(props: IndexProps) {

export async function getStaticProps() {
let listings = []
let thisJurisdiction = null
try {
const response = await axios.get(process.env.listingServiceUrl, {
const listingsResponse = await axios.get(process.env.listingServiceUrl, {
params: {
view: "base",
limit: "all",
Expand All @@ -104,11 +119,18 @@ export async function getStaticProps() {
return qs.stringify(params)
},
})

listings = response?.data?.items ? response.data.items : []
const jurisdictionName = process.env.jurisdictionName
const jurisdiction = await axios.get(
`${process.env.backendApiBase}/jurisdictions/byName/${jurisdictionName}`
)
thisJurisdiction = jurisdiction?.data ? jurisdiction.data : null
listings = listingsResponse?.data?.items ? listingsResponse.data.items : []
} catch (error) {
console.error(error)
}

return { props: { listings }, revalidate: process.env.cacheRevalidate }
return {
props: { listings, jurisdiction: thisJurisdiction },
revalidate: process.env.cacheRevalidate,
}
}
6 changes: 6 additions & 0 deletions ui-components/src/global/homepage.scss
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
.homepage-extra {
@apply text-center;
@apply text-base;
@apply flex;
@apply flex-col;
@apply justify-center;
@apply items-center;

@screen md {
@apply text-lg;
@apply flex-row;
@apply justify-around;
}
}
2 changes: 2 additions & 0 deletions ui-components/src/locales/general.json
Original file line number Diff line number Diff line change
Expand Up @@ -1300,6 +1300,8 @@
"seeRentalListings": "See Rentals",
"title": "Apply for affordable housing in",
"seeMoreOpportunities": "See more rental and ownership housing opportunities",
"signUp": "Get emailed whenever a new listing is posted",
"signUpToday": "Sign up today",
"viewAdditionalHousing": "View Additional Housing Opportunities and Resources"
},
"whatToExpect": {
Expand Down

0 comments on commit ef4901d

Please sign in to comment.