-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: made sync service abstract for any type
- Loading branch information
1 parent
21f277f
commit 24c9f3c
Showing
7 changed files
with
307 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* SudoSOS back-end API service. | ||
* Copyright (C) 2024 Study association GEWIS | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
* | ||
* @license | ||
*/ | ||
|
||
import User from '../../../entity/user/user'; | ||
import { In } from 'typeorm'; | ||
import log4js, { Logger } from 'log4js'; | ||
import SyncManager from '../sync-manager'; | ||
import { UserSyncService } from './user-sync-service'; | ||
|
||
export default class UserSyncManager extends SyncManager<User, UserSyncService> { | ||
|
||
protected logger: Logger = log4js.getLogger('UserSyncManager'); | ||
|
||
async getTargets(): Promise<User[]> { | ||
const userTypes = this.services.flatMap((s) => s.targets); | ||
this.logger.trace('Syncing users of types', userTypes); | ||
return this.manager.find(User, { where: { type: In(userTypes) } }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* SudoSOS back-end API service. | ||
* Copyright (C) 2024 Study association GEWIS | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
* | ||
* @license | ||
*/ | ||
|
||
/** | ||
* This is the module page of the abstract sync-service. | ||
* | ||
* @module internal/user-user-service | ||
*/ | ||
|
||
import User, { UserType } from '../../../entity/user/user'; | ||
import { SyncService } from '../sync-service'; | ||
|
||
/** | ||
* UserSyncService interface. | ||
* | ||
* Specific sync service for users. | ||
*/ | ||
export abstract class UserSyncService extends SyncService<User> { | ||
|
||
targets: UserType[]; | ||
|
||
guard(user: User): Promise<boolean> { | ||
return Promise.resolve(this.targets.includes(user.type)); | ||
} | ||
} |
Oops, something went wrong.