import { Base } from './base'; import { Licence as LicenceModel } from './models/licence'; import { mapAllocateSeatResponse } from './mappers/allocate-seat'; import { MembershipAdminLicence, MembershipLicenceResponse } from './types/licence'; import { mapLicenceResponse } from './mappers/licence'; /** Class representing Licence Service request. */ export class Licence extends Base { private membershipApi = this.config.get('membershipApi'); private licenceApiKey = this.config.get('licenceApiKey'); /** * This function is the public method for fetching assigned licences that a user is admin to. * @param userId User's ID. * @returns admin licences */ public async getUserAdminLicences(userId: string): Promise> { const url = `${this.membershipApi}/licences?adminuserid=${userId}`; const response = await this.requestGet({ key: this.licenceApiKey, url }); return response.accessLicences; } /** * This function is the public method for allocating a seat on a licence. * @param licenceId The ID of the Licence. * @param userId User's ID. * @param accessDuration Amount of time the user will be allocated the seat on the licence. * @returns Object containing accessLicenceId, userId, joinedDate and seatExpiryDate properties. */ public async allocateSeat(licenceId: string, userId: string, accessDuration: string): Promise { const url = `${this.membershipApi}/licences/${licenceId}/seats/allocate`; const body = { userId, accessDuration }; const response = await this.requestPost({ key: this.licenceApiKey, url, body }); return mapAllocateSeatResponse(response); } /** * Maps a AIM GraphQL response to the licence model. * @param licenceData Response to licence request. * @throws {InvalidResponseError} If the membership request does not return the expected response. * @returns Licence instance. */ public mapLicenceResponse(licenceData: any): LicenceModel { return mapLicenceResponse(licenceData); } }