Skip to content

Commit 9963866

Browse files
committed
feat: add access to new editions of instruments, for groups that have access to prev edition
1 parent 67bc1ab commit 9963866

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

apps/api/src/instruments/instruments.service.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ type InstrumentQuery<TKind extends InstrumentKind> = {
4646
@Injectable()
4747
export class InstrumentsService {
4848
constructor(
49+
@InjectModel('Group') private readonly groupModel: Model<'Group'>,
4950
@InjectModel('Instrument') private readonly instrumentModel: Model<'Instrument'>,
5051
private readonly cryptoService: CryptoService,
5152
private readonly loggingService: LoggingService,
@@ -87,6 +88,21 @@ export class InstrumentsService {
8788
if (!result.success) {
8889
throw new UnprocessableEntityException(result.message);
8990
}
91+
} else if (instance.internal.edition > 1) {
92+
await this.groupModel.updateMany({
93+
data: {
94+
accessibleInstrumentIds: {
95+
push: [id]
96+
}
97+
},
98+
where: {
99+
accessibleInstrumentIds: {
100+
has: this.generateScalarInstrumentId({
101+
internal: { edition: instance.internal.edition - 1, name: instance.internal.name }
102+
})
103+
}
104+
}
105+
});
90106
}
91107

92108
await this.instrumentModel.create({ data: { bundle, id } });

0 commit comments

Comments
 (0)