Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: geocoding sj #681

Merged
merged 6 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions api/prisma/seed-staging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ export const stagingSeed = async (
data: jurisdictionFactory(jurisdictionName, [UserRoleEnum.admin]),
});
// add additional jurisdictions
const additionalJurisdiction = await prismaClient.jurisdictions.create({
const sanMateoJurisdiction = await prismaClient.jurisdictions.create({
data: jurisdictionFactory('San Mateo'),
});
await prismaClient.jurisdictions.create({
const sanJoseJurisdiction = await prismaClient.jurisdictions.create({
data: jurisdictionFactory('San Jose'),
});
// create admin user
Expand All @@ -60,7 +60,11 @@ export const stagingSeed = async (
roles: { isAdmin: true },
email: '[email protected]',
confirmedAt: new Date(),
jurisdictionIds: [jurisdiction.id, additionalJurisdiction.id],
jurisdictionIds: [
jurisdiction.id,
sanMateoJurisdiction.id,
sanJoseJurisdiction.id,
],
acceptedTerms: true,
password: 'abcdef',
}),
Expand Down Expand Up @@ -128,7 +132,7 @@ export const stagingSeed = async (
data: amiChartFactory(10, jurisdiction.id),
});
await prismaClient.amiChart.create({
data: amiChartFactory(8, additionalJurisdiction.id),
data: amiChartFactory(8, sanJoseJurisdiction.id),
});
// Create map layers
await prismaClient.mapLayers.create({
Expand Down Expand Up @@ -1217,7 +1221,7 @@ export const stagingSeed = async (
},
email: '[email protected]',
confirmedAt: new Date(),
jurisdictionIds: [jurisdiction.id, additionalJurisdiction.id],
jurisdictionIds: [jurisdiction.id, sanMateoJurisdiction.id],
acceptedTerms: true,
listings: [savedListing.id],
}),
Expand Down
13 changes: 13 additions & 0 deletions api/src/controllers/script-runner.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export class ScirptRunnerController {
body.description,
);
}

@Put('updateCodeExpirationTranslations')
@ApiOperation({
summary:
Expand Down Expand Up @@ -185,4 +186,16 @@ export class ScirptRunnerController {
req,
);
}

@Put('insertSanJoseMapLayers')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These historically have been accompanied by a test in core

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test added

@ApiOperation({
summary: 'A script that adds map layers for San Jose',
operationId: 'insertSanJoseMapLayers',
})
@ApiOkResponse({ type: SuccessDTO })
async insertSanJoseMapLayers(
@Request() req: ExpressRequest,
): Promise<SuccessDTO> {
return await this.scriptRunnerService.insertSanJoseMapLayers(req);
}
}
5,925 changes: 5,925 additions & 0 deletions api/src/data/SanJoseDistrict1.json

Large diffs are not rendered by default.

4,617 changes: 4,617 additions & 0 deletions api/src/data/SanJoseDistrict10.json

Large diffs are not rendered by default.

7,730 changes: 7,730 additions & 0 deletions api/src/data/SanJoseDistrict2.json

Large diffs are not rendered by default.

2,138 changes: 2,138 additions & 0 deletions api/src/data/SanJoseDistrict3.json

Large diffs are not rendered by default.

10,124 changes: 10,124 additions & 0 deletions api/src/data/SanJoseDistrict4.json

Large diffs are not rendered by default.

7,681 changes: 7,681 additions & 0 deletions api/src/data/SanJoseDistrict5.json

Large diffs are not rendered by default.

6,445 changes: 6,445 additions & 0 deletions api/src/data/SanJoseDistrict6.json

Large diffs are not rendered by default.

2,267 changes: 2,267 additions & 0 deletions api/src/data/SanJoseDistrict7.json

Large diffs are not rendered by default.

2,878 changes: 2,878 additions & 0 deletions api/src/data/SanJoseDistrict8.json

Large diffs are not rendered by default.

5,626 changes: 5,626 additions & 0 deletions api/src/data/SanJoseDistrict9.json

Large diffs are not rendered by default.

11,351 changes: 11,351 additions & 0 deletions api/src/data/SanJoseRedlined.json

Large diffs are not rendered by default.

61 changes: 61 additions & 0 deletions api/src/services/script-runner.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ import { AmiChartCreate } from '../dtos/ami-charts/ami-chart-create.dto';
import { AmiChartService } from './ami-chart.service';
import { AmiChartUpdate } from '../dtos/ami-charts/ami-chart-update.dto';
import { AmiChartUpdateImportDTO } from '../dtos/script-runner/ami-chart-update-import.dto';
import sanJoseRedlined from '../data/SanJoseRedlined.json';
import district1 from '../data/SanJoseDistrict1.json';
import district2 from '../data/SanJoseDistrict2.json';
import district3 from '../data/SanJoseDistrict3.json';
import district4 from '../data/SanJoseDistrict4.json';
import district5 from '../data/SanJoseDistrict5.json';
import district6 from '../data/SanJoseDistrict6.json';
import district7 from '../data/SanJoseDistrict7.json';
import district8 from '../data/SanJoseDistrict8.json';
import district9 from '../data/SanJoseDistrict9.json';
import district10 from '../data/SanJoseDistrict10.json';

/**
this is the service for running scripts
Expand Down Expand Up @@ -630,6 +641,56 @@ export class ScriptRunnerService {
);
return { success: true };
}
/**
*
* @param req incoming request object
* @returns successDTO
* @description Adds 11 new map layers for San Jose
*/
async insertSanJoseMapLayers(req: ExpressRequest): Promise<SuccessDTO> {
const requestingUser = mapTo(User, req['user']);
await this.markScriptAsRunStart('san jose map layers', requestingUser);

const sjId = await this.prisma.jurisdictions.findFirst({
select: {
id: true,
},
where: { name: 'San Jose' },
});

await this.prisma.mapLayers.create({
data: {
name: 'San Jose Redlined',
jurisdictionId: sjId.id,
featureCollection: sanJoseRedlined,
},
});

const councilDistrictMaps = [
district1,
district2,
district3,
district4,
district5,
district6,
district7,
district8,
district9,
district10,
];
councilDistrictMaps.forEach(async (disctict, index) => {
await this.prisma.mapLayers.create({
data: {
name: `San Jose District ${index + 1}`,
jurisdictionId: sjId.id,
featureCollection: disctict,
},
});
});

await this.markScriptAsComplete('san jose map layers', requestingUser);
return { success: true };
}

/**
this is simply an example
Expand Down
28 changes: 28 additions & 0 deletions api/test/unit/services/script-runner.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -841,4 +841,32 @@ describe('Testing script runner service', () => {
},
});
});

describe('insertSanJoseMapLayers', () => {
it('should insert all san jose maps', async () => {
const id = randomUUID();
const jurisdictionId = randomUUID();
prisma.scriptRuns.findUnique = jest.fn().mockResolvedValue(null);
prisma.scriptRuns.create = jest.fn().mockResolvedValue(null);
prisma.scriptRuns.update = jest.fn().mockResolvedValue(null);
prisma.jurisdictions.findFirst = jest
.fn()
.mockResolvedValue({ id: jurisdictionId });
prisma.mapLayers.create = jest.fn();
await service.insertSanJoseMapLayers({
user: {
id,
} as unknown as User,
} as unknown as ExpressRequest);

expect(prisma.mapLayers.create).toHaveBeenCalledTimes(11);
expect(prisma.mapLayers.create).toHaveBeenCalledWith({
data: {
name: 'San Jose Redlined',
jurisdictionId: jurisdictionId,
featureCollection: expect.anything(),
},
});
});
});
});
3 changes: 2 additions & 1 deletion api/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"strictBindCallApply": false,
"forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": false,
"esModuleInterop": true
"esModuleInterop": true,
"resolveJsonModule": true,
},
"exclude": ["node_modules", "dist"]
}
18 changes: 16 additions & 2 deletions shared-helpers/src/types/backend-swagger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2311,7 +2311,6 @@ export class ScriptRunnerService {
axios(configs, resolve, reject)
})
}

/**
* A script that updates the preference keys for applications on Spark Homes
*/
Expand All @@ -2327,6 +2326,22 @@ export class ScriptRunnerService {

configs.data = data

axios(configs, resolve, reject)
})
}
/**
* A script that adds map layers for San Jose
*/
insertSanJoseMapLayers(options: IRequestOptions = {}): Promise<SuccessDTO> {
return new Promise((resolve, reject) => {
let url = basePath + "/scriptRunner/insertSanJoseMapLayers"

const configs: IRequestConfig = getConfigs("put", "application/json", url, options)

let data = null

configs.data = data

axios(configs, resolve, reject)
})
}
Expand Down Expand Up @@ -5939,7 +5954,6 @@ export interface AmiChartImportDTO {
jurisdictionId: string
}


export interface AmiChartUpdateImportDTO {
/** */
values: string
Expand Down
2 changes: 1 addition & 1 deletion sites/partners/cypress/e2e/default/09-lottery.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe("Lottery Tests", () => {
.should("be.visible")
.type("[email protected]", { force: true })
cy.getByID("[email protected]").first().click()
cy.getByTestId("listings-all-Alameda").check()
cy.getByTestId("listings-all-Alameda").check({ force: true })
cy.getByID("save-user").click()

// Login as partner and view lottery tab
Expand Down
10 changes: 6 additions & 4 deletions sites/partners/src/components/settings/PreferenceDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -731,10 +731,12 @@ const PreferenceDrawer = ({
mapLayers
? [
{ label: "", value: "" },
...mapLayers.map((layer) => ({
label: layer.name,
value: layer.id,
})),
...mapLayers
.sort((a, b) => a.name.localeCompare(b.name))
.map((layer) => ({
label: layer.name,
value: layer.id,
})),
]
: [{ label: "", value: "" }]
}
Expand Down
Loading