-
Notifications
You must be signed in to change notification settings - Fork 70
/
event.repository.ts
111 lines (101 loc) · 3.17 KB
/
event.repository.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Copyright (c) 2023 Sourcefuse Technologies
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
import {Getter, inject} from '@loopback/core';
import {
BelongsToAccessor,
HasManyRepositoryFactory,
juggler,
repository,
} from '@loopback/repository';
import {
ConditionalAuditRepositoryMixin,
IAuditMixinOptions,
} from '@sourceloop/audit-log';
import {
DefaultUserModifyCrudRepository,
IAuthUserWithPermissions,
} from '@sourceloop/core';
import {AuthenticationBindings} from 'loopback4-authentication';
import {SchedulerDatasourceName} from '../keys';
import {Attachment, Attendee, Calendar, Event, EventRelations} from '../models';
import {AttachmentRepository} from './attachment.repository';
import {AttendeeRepository} from './attendee.repository';
import {AuditLogRepository} from './audit.repository';
import {CalendarRepository} from './calendar.repository';
const EventAuditOpts: IAuditMixinOptions = {
actionKey: 'Event_Logs',
};
export class EventRepository extends ConditionalAuditRepositoryMixin(
DefaultUserModifyCrudRepository<
Event,
typeof Event.prototype.id,
EventRelations
>,
EventAuditOpts,
) {
public readonly calendar: BelongsToAccessor<
Calendar,
typeof Event.prototype.id
>;
public readonly parentEvent: BelongsToAccessor<
Event,
typeof Event.prototype.id
>;
public readonly attendees: HasManyRepositoryFactory<
Attendee,
typeof Event.prototype.id
>;
public readonly attachments: HasManyRepositoryFactory<
Attachment,
typeof Event.prototype.id
>;
constructor(
@inject(`datasources.${SchedulerDatasourceName}`)
dataSource: juggler.DataSource,
@inject.getter(AuthenticationBindings.CURRENT_USER)
protected readonly getCurrentUser: Getter<
IAuthUserWithPermissions | undefined
>,
@repository.getter('CalendarRepository')
protected calendarRepositoryGetter: Getter<CalendarRepository>,
@repository.getter('AttendeeRepository')
protected attendeeRepositoryGetter: Getter<AttendeeRepository>,
@repository.getter('AttachmentRepository')
protected attachmentRepositoryGetter: Getter<AttachmentRepository>,
@repository.getter('AuditLogRepository')
public getAuditLogRepository: Getter<AuditLogRepository>,
) {
super(Event, dataSource, getCurrentUser);
this.attachments = this.createHasManyRepositoryFactoryFor(
'attachments',
attachmentRepositoryGetter,
);
this.registerInclusionResolver(
'attachments',
this.attachments.inclusionResolver,
);
this.attendees = this.createHasManyRepositoryFactoryFor(
'attendees',
attendeeRepositoryGetter,
);
this.registerInclusionResolver(
'attendees',
this.attendees.inclusionResolver,
);
this.parentEvent = this.createBelongsToAccessorFor(
'parentEvent',
Getter.fromValue(this),
);
this.registerInclusionResolver(
'parentEvent',
this.parentEvent.inclusionResolver,
);
this.calendar = this.createBelongsToAccessorFor(
'calendar',
calendarRepositoryGetter,
);
this.registerInclusionResolver('calendar', this.calendar.inclusionResolver);
}
}