Skip to content

Commit

Permalink
store searchable_by in searches made and clean search_made__appellati…
Browse files Browse the repository at this point in the history
…ons when no appellation is provided
  • Loading branch information
JeromeBu committed Sep 20, 2024
1 parent 578aaf1 commit 7d232a2
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions back/src/config/pg/kysely/model/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ interface SearchesMade extends WithAcquisition {
lon: number | null;
distance: number | null;
gps: string | null;
searchable_by: "jobSeekers" | "students" | null;
}

interface UsersAgencies {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { MigrationBuilder } from "node-pg-migrate";

export async function up(pgm: MigrationBuilder): Promise<void> {
pgm.createType("searchable_by", ["students", "jobSeekers"]);
pgm.addColumn("searches_made", {
searchable_by: { type: "searchable_by" },
});

await pgm.db.query(`
DELETE FROM searches_made__appellation_code where appellation_code is null;
`);
pgm.alterColumn("searches_made__appellation_code", "appellation_code", {
notNull: true,
});
}

export async function down(pgm: MigrationBuilder): Promise<void> {
pgm.dropColumn("searches_made", "searchable_by");
pgm.dropType("searchable_by");
pgm.alterColumn("searches_made__appellation_code", "appellation_code", {
notNull: false,
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class PgSearchMadeRepository implements SearchMadeRepository {
public async insertSearchMade(searchMade: SearchMadeEntity) {
await this.#insertSearchMade(searchMade);

if (searchMade.appellationCodes) {
if (searchMade.appellationCodes && searchMade.appellationCodes.length > 0) {
await this.#insertAppellationCodes(
searchMade.id,
searchMade.appellationCodes,
Expand All @@ -34,6 +34,7 @@ export class PgSearchMadeRepository implements SearchMadeRepository {
sorted_by: searchMade.sortedBy,
address: searchMade.place,
number_of_results: searchMade.numberOfResults,
searchable_by: searchMade.establishmentSearchableBy,
acquisition_keyword: searchMade.acquisitionKeyword,
acquisition_campaign: searchMade.acquisitionCampaign,
...(hasSearchMadeGeoParams(searchMade)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class SearchImmersion extends TransactionalUseCase<
needsToBeSearched: true,
apiConsumerName: apiConsumer?.name,
numberOfResults:
voluntaryToImmersion !== false
voluntaryToImmersion !== false // cases where voluntaryToImmersion is undefined and true
? repositorySearchResults.length
: lbbSearchResults.length,
});
Expand Down

0 comments on commit 7d232a2

Please sign in to comment.