Skip to content

Commit a996c2c

Browse files
rdonigianbryanjnelson
authored andcommitted
add blacklist query to handler
1 parent 3cd692f commit a996c2c

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

src/components/project/handlers/set-department-id.handler.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,16 @@ export class SetDepartmentId implements IEventHandler<SubscribedEvent> {
105105
.where({ 'deptIdNode.value': not(isNull()) })
106106
.return(collect('deptIdNode.value').as('used')),
107107
)
108-
// Distill to available
109-
.with('[id in enumerated where not id in used][0] as next')
108+
// Get blacklisted IDs
109+
.subQuery((sub) =>
110+
sub
111+
.match(node('blacklist', 'BlacklistDepartmentId'))
112+
.return(collect('blacklist.departmentId').as('blacklisted')),
113+
)
114+
// Distill to available (excluding both used AND blacklisted)
115+
.with(
116+
'[id in enumerated where not id in used and not id in blacklisted][0] as next',
117+
)
110118
// collapse cardinality to zero if none available
111119
.raw('unwind next as nextId')
112120

src/components/project/migrations/create-used-dept-id-list.migration.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ export class CreateUsedDeptIdListMigration extends BaseMigration {
2828

2929
const intaactList: ExternalDepartmentId[] = intaactRows.flatMap((row) => {
3030
const [id, name] = row.split(',');
31-
if (id) {
32-
return { id, name };
33-
}
34-
return [];
31+
return id ? { id, name } : [];
3532
});
3633

3734
const prunedIntaactList = intaactList.flatMap((row) =>
@@ -41,15 +38,14 @@ export class CreateUsedDeptIdListMigration extends BaseMigration {
4138
await this.db
4239
.query()
4340
.unwind(prunedIntaactList, 'dept')
44-
.create(node('blacklist', 'BlacklistDepartmentId'))
41+
.create(node('external', 'ExternalDepartmentId'))
4542
.setValues({
46-
'blacklist.id': variable(apoc.create.uuid()),
47-
'blacklist.departmentId': variable('dept.id'),
48-
'blacklist.departmentName': variable('dept.name'),
49-
'blacklist.createdAt': Date.now(),
50-
'blacklist.createdBy': 'bulk_import',
43+
'external.id': variable(apoc.create.uuid()),
44+
'external.departmentId': variable('dept.id'),
45+
'external.name': variable('dept.name'),
46+
'external.createdAt': variable('datetime()'),
5147
})
52-
.return('count(blacklist) as created')
48+
.return('count(external) as created')
5349
.executeAndLogStats();
5450
}
5551
}

0 commit comments

Comments
 (0)