Skip to content

Commit c030c8f

Browse files
feat: allow for instruments to be add to call without being selectable (#1055)
Co-authored-by: Rasmia Kulan <69144386+RasmiaKulan@users.noreply.github.com> Co-authored-by: Rasmia Kulan <rasmia.kulan@stfc.ac.uk>
1 parent 76c9f20 commit c030c8f

File tree

15 files changed

+81
-14
lines changed

15 files changed

+81
-14
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
DO
2+
$$
3+
BEGIN
4+
IF register_patch('0180_MarkInstrumentsAsUnselectable.sql', 'TCMeldrum', 'Mark instruments as unselecable for instrument picker', '2025-05-25') THEN
5+
BEGIN
6+
7+
ALTER TABLE instruments
8+
ADD COLUMN selectable boolean DEFAULT true;
9+
10+
END;
11+
END IF;
12+
END;
13+
$$
14+
LANGUAGE plpgsql;

apps/backend/src/datasources/InstrumentDataSource.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ export interface InstrumentDataSource {
1919
): Promise<{ totalCount: number; instruments: Instrument[] }>;
2020
getUserInstruments(userId: number): Promise<Instrument[]>;
2121
getInstrumentsByCallId(
22-
callIds: number[]
22+
callIds: number[],
23+
selectableOnly?: boolean
2324
): Promise<InstrumentWithAvailabilityTime[]>;
2425
getCallsByInstrumentId(
2526
instrumentId: number,

apps/backend/src/datasources/mockups/InstrumentDataSource.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,17 @@ export const dummyInstrument = new Instrument(
1616
'Dummy instrument 1',
1717
'instrument_1',
1818
'This is test instrument.',
19-
1
19+
1,
20+
true
2021
);
2122

2223
export const dummyInstrument2 = new Instrument(
2324
2,
2425
'Dummy instrument 2',
2526
'instrument_2',
2627
'This is test instrument.',
27-
1
28+
1,
29+
true
2830
);
2931

3032
export const dummyInstrumentWithAvailabilityTime =

apps/backend/src/datasources/postgres/InstrumentDataSource.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ export default class PostgresInstrumentDataSource
4141
instrument.name,
4242
instrument.short_code,
4343
instrument.description,
44-
instrument.manager_user_id
44+
instrument.manager_user_id,
45+
instrument.selectable
4546
);
4647
}
4748

@@ -80,6 +81,7 @@ export default class PostgresInstrumentDataSource
8081
short_code: args.shortCode,
8182
description: args.description,
8283
manager_user_id: args.managerUserId,
84+
selectable: !!args.selectable,
8385
})
8486
.into('instruments')
8587
.returning('*');
@@ -153,7 +155,8 @@ export default class PostgresInstrumentDataSource
153155
}
154156

155157
async getInstrumentsByCallId(
156-
callIds: number[]
158+
callIds: number[],
159+
selectableOnly?: boolean
157160
): Promise<InstrumentWithAvailabilityTime[]> {
158161
return database
159162
.select([
@@ -170,6 +173,11 @@ export default class PostgresInstrumentDataSource
170173
'i.instrument_id': 'chi.instrument_id',
171174
})
172175
.whereIn('chi.call_id', callIds)
176+
.modify((query) => {
177+
if (selectableOnly) {
178+
query.andWhere('i.selectable', true);
179+
}
180+
})
173181
.distinct('i.instrument_id')
174182
.then((instruments: InstrumentWithAvailabilityTimeRecord[]) => {
175183
const result = instruments.map((instrument) =>
@@ -286,6 +294,7 @@ export default class PostgresInstrumentDataSource
286294
short_code: instrument.shortCode,
287295
description: instrument.description,
288296
manager_user_id: instrument.managerUserId,
297+
selectable: instrument.selectable,
289298
},
290299
['*']
291300
)

apps/backend/src/datasources/postgres/records.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,7 @@ export interface InstrumentRecord {
484484
readonly description: string;
485485
readonly manager_user_id: number;
486486
readonly full_count: number;
487+
readonly selectable: boolean;
487488
}
488489

489490
export interface InstrumentHasProposalRecord {
@@ -823,7 +824,8 @@ export const createInstrumentObject = (instrument: InstrumentRecord) => {
823824
instrument.name,
824825
instrument.short_code,
825826
instrument.description,
826-
instrument.manager_user_id
827+
instrument.manager_user_id,
828+
instrument.selectable
827829
);
828830
};
829831

apps/backend/src/models/Instrument.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ export class Instrument {
44
public name: string,
55
public shortCode: string,
66
public description: string,
7-
public managerUserId: number
7+
public managerUserId: number,
8+
public selectable?: boolean
89
) {}
910
}
1011

apps/backend/src/models/questionTypes/InstrumentPicker.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,10 @@ export const instrumentPickerDefinition: Question<DataType.INSTRUMENT_PICKER> =
6464
Tokens.InstrumentDataSource
6565
);
6666

67-
const instruments = await instrumentDataSource.getInstrumentsByCallId([
68-
callId,
69-
]);
67+
const instruments = await instrumentDataSource.getInstrumentsByCallId(
68+
[callId],
69+
true
70+
);
7071

7172
return {
7273
...config,

apps/backend/src/mutations/InstrumentMutations.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ describe('Test Instrument Mutations', () => {
5959
shortCode: '2020-06-15',
6060
description: 'Test instrument description',
6161
managerUserId: 1,
62+
selectable: true,
6263
};
6364

6465
return expect(
@@ -74,6 +75,7 @@ describe('Test Instrument Mutations', () => {
7475
description: 'Test instrument description 1',
7576
managerUserId: 1,
7677
updateTechReview: true,
78+
selectable: true,
7779
};
7880

7981
return expect(

apps/backend/src/resolvers/mutations/CreateInstrumentMutation.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ export class CreateInstrumentArgs {
2424

2525
@Field(() => Int)
2626
public managerUserId: number;
27+
28+
@Field(() => Boolean, { nullable: true, defaultValue: true })
29+
public selectable?: boolean;
2730
}
2831

2932
@Resolver()

apps/backend/src/resolvers/mutations/UpdateInstrumentMutation.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ export class UpdateInstrumentArgs {
3131

3232
@Field(() => Boolean)
3333
public updateTechReview: boolean;
34+
35+
@Field(() => Boolean, { nullable: true })
36+
public selectable?: boolean;
3437
}
3538

3639
@ArgsType()

0 commit comments

Comments
 (0)