/** * Swagger Petstore - OpenAPI 3.0Lib * * This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ). */ import { ApiResponse, RequestOptions } from '../core.js'; import { User, userSchema } from '../models/user.js'; import { array, bigint, number, optional, string } from '../schema.js'; import { BaseApi } from './baseApi.js'; import { ApiError } from '@apimatic/core'; export class UserApi extends BaseApi { /** * This can only be done by the logged in user. * * @param id * @param username * @param firstName * @param lastName * @param email * @param password * @param phone * @param userStatus User Status * @return Response from the API call */ async createUser( id?: bigint, username?: string, firstName?: string, lastName?: string, email?: string, password?: string, phone?: string, userStatus?: number, requestOptions?: RequestOptions ): Promise> { const req = this.createRequest('POST', '/user'); const mapped = req.prepareArgs({ id: [id, optional(bigint())], username: [username, optional(string())], firstName: [firstName, optional(string())], lastName: [lastName, optional(string())], email: [email, optional(string())], password: [password, optional(string())], phone: [phone, optional(string())], userStatus: [userStatus, optional(number())], }); req.header('Content-Type', 'application/x-www-form-urlencoded'); req.form({ id: mapped.id, username: mapped.username, firstName: mapped.firstName, lastName: mapped.lastName, email: mapped.email, password: mapped.password, phone: mapped.phone, userStatus: mapped.userStatus, }); req.defaultToError(ApiError, 'Unexpected error'); req.authenticate([]); return req.callAsJson(userSchema, requestOptions); } /** * Creates list of users with given input array. * * @param body * @return Response from the API call */ async createUsersWithListInput( body?: User[], requestOptions?: RequestOptions ): Promise> { const req = this.createRequest('POST', '/user/createWithList'); const mapped = req.prepareArgs({ body: [body, optional(array(userSchema))], }); req.header('Content-Type', 'application/json'); req.json(mapped.body); req.defaultToError(ApiError, 'Unexpected error'); req.authenticate([]); return req.callAsJson(userSchema, requestOptions); } /** * Log into the system. * * @param username The user name for login * @param password The password for login in clear text * @return Response from the API call */ async loginUser( username?: string, password?: string, requestOptions?: RequestOptions ): Promise> { const req = this.createRequest('GET', '/user/login'); const mapped = req.prepareArgs({ username: [username, optional(string())], password: [password, optional(string())], }); req.query('username', mapped.username); req.query('password', mapped.password); req.throwOn(400, ApiError, 'Invalid username/password supplied'); req.defaultToError(ApiError, 'Unexpected error'); req.authenticate([]); return req.callAsXml('response', string(), requestOptions); } /** * Log user out of the system. * * @return Response from the API call */ async logoutUser( requestOptions?: RequestOptions ): Promise> { const req = this.createRequest('GET', '/user/logout'); req.defaultToError(ApiError, 'Unexpected error'); req.authenticate([]); return req.call(requestOptions); } /** * Get user detail based on username. * * @param usersname The username that needs to be processed * @return Response from the API call */ async getUserByName( usersname: string, requestOptions?: RequestOptions ): Promise> { const req = this.createRequest('GET'); const mapped = req.prepareArgs({ usersname: [usersname, string()] }); req.appendTemplatePath`/user/${mapped.usersname}`; req.throwOn(400, ApiError, 'Invalid username supplied'); req.throwOn(404, ApiError, 'User not found'); req.defaultToError(ApiError, 'Unexpected error'); req.authenticate([]); return req.callAsJson(userSchema, requestOptions); } /** * This can only be done by the logged in user. * * @param usersname The username that needs to be processed * @param id * @param username * @param firstName * @param lastName * @param email * @param password * @param phone * @param userStatus User Status * @return Response from the API call */ async updateUser( usersname: string, id?: bigint, username?: string, firstName?: string, lastName?: string, email?: string, password?: string, phone?: string, userStatus?: number, requestOptions?: RequestOptions ): Promise> { const req = this.createRequest('PUT'); const mapped = req.prepareArgs({ usersname: [usersname, string()], id: [id, optional(bigint())], username: [username, optional(string())], firstName: [firstName, optional(string())], lastName: [lastName, optional(string())], email: [email, optional(string())], password: [password, optional(string())], phone: [phone, optional(string())], userStatus: [userStatus, optional(number())], }); req.header('Content-Type', 'application/x-www-form-urlencoded'); req.form({ id: mapped.id, username: mapped.username, firstName: mapped.firstName, lastName: mapped.lastName, email: mapped.email, password: mapped.password, phone: mapped.phone, userStatus: mapped.userStatus, }); req.appendTemplatePath`/user/${mapped.usersname}`; req.throwOn(400, ApiError, 'bad request'); req.throwOn(404, ApiError, 'user not found'); req.defaultToError(ApiError, 'Unexpected error'); req.authenticate([]); return req.call(requestOptions); } /** * This can only be done by the logged in user. * * @param usersname The username that needs to be processed * @return Response from the API call */ async deleteUser( usersname: string, requestOptions?: RequestOptions ): Promise> { const req = this.createRequest('DELETE'); const mapped = req.prepareArgs({ usersname: [usersname, string()] }); req.appendTemplatePath`/user/${mapped.usersname}`; req.throwOn(400, ApiError, 'Invalid username supplied'); req.throwOn(404, ApiError, 'User not found'); req.defaultToError(ApiError, 'Unexpected error'); req.authenticate([]); return req.call(requestOptions); } }