|
| 1 | +import { Credentials } from '@models'; |
| 2 | +import { |
| 3 | + addDatatoDatabase, |
| 4 | + editDatainDatabase, |
| 5 | + deleteDatafromDatabase, |
| 6 | +} from '@plugins/auth/helpers'; |
| 7 | +import { credentials as credentialPolicies } from '@plugins/templates/policies'; |
| 8 | + |
| 9 | +import type { |
| 10 | + ICredentials, |
| 11 | + ICredentialsDoc, |
| 12 | + ICredentialsModel, |
| 13 | +} from '@models/credential/types'; |
| 14 | +import type { IUserDoc } from '@models/user/types'; |
| 15 | + |
| 16 | +/** |
| 17 | + * Add Credentials in the Database |
| 18 | + * |
| 19 | + * @param {IUserDoc} admin - Admin user to Perform the Action |
| 20 | + * @param {ICredentials} data - Credentials Data |
| 21 | + * @returns {Promise<ICredentialsDoc>} - Credentials Document from the Database |
| 22 | + */ |
| 23 | +function add(admin: IUserDoc, data: ICredentials): Promise<ICredentialsDoc> { |
| 24 | + const policies = [credentialPolicies.add]; |
| 25 | + return addDatatoDatabase<ICredentials, ICredentialsDoc, ICredentialsModel>( |
| 26 | + Credentials, |
| 27 | + data, |
| 28 | + admin, |
| 29 | + policies, |
| 30 | + ); |
| 31 | +} |
| 32 | + |
| 33 | +/** |
| 34 | + * Edit Credentials in the Database |
| 35 | + * |
| 36 | + * @param {IUserDoc} admin - Admin User to Perform the Action |
| 37 | + * @param {ICredentialsDoc} data - Data to be Modified |
| 38 | + * @param {Partial<ICredentialsDoc>} modifiedData - Modified Object |
| 39 | + * @returns {Promise<boolean>} - true/false |
| 40 | + */ |
| 41 | +function edit( |
| 42 | + admin: IUserDoc, |
| 43 | + data: ICredentialsDoc, |
| 44 | + modifiedData: Partial<ICredentialsDoc>, |
| 45 | +): Promise<boolean> { |
| 46 | + const policies = [credentialPolicies.edit]; |
| 47 | + return editDatainDatabase<ICredentialsDoc, ICredentialsModel>( |
| 48 | + Credentials, |
| 49 | + data, |
| 50 | + modifiedData, |
| 51 | + admin, |
| 52 | + policies, |
| 53 | + ); |
| 54 | +} |
| 55 | + |
| 56 | +/** |
| 57 | + * Delete Credentials from the Database |
| 58 | + * |
| 59 | + * @param {IUserDoc} admin - Admin User to Perform the Action |
| 60 | + * @param {ICredentialsDoc} data - Data to be Deleted |
| 61 | + * @returns {Promise<boolean>} - true/false |
| 62 | + */ |
| 63 | +function remove(admin: IUserDoc, data: ICredentialsDoc): Promise<boolean> { |
| 64 | + const policies = [credentialPolicies.remove]; |
| 65 | + return deleteDatafromDatabase<ICredentialsDoc, ICredentialsModel>( |
| 66 | + Credentials, |
| 67 | + data, |
| 68 | + admin, |
| 69 | + policies, |
| 70 | + ); |
| 71 | +} |
| 72 | + |
| 73 | +export default { |
| 74 | + add, |
| 75 | + edit, |
| 76 | + remove, |
| 77 | +}; |
0 commit comments