import { BaseResource } from '@gitbeaker/requester-utils'; import { RequestHelper } from '../infrastructure'; import type { GitlabAPIResponse, ShowExpanded, Sudo } from '../infrastructure'; export interface UserEmailSchema extends Record { id: number; email: string; confirmed_at: string; } const url = (userId?: number) => (userId ? `users/${userId}/emails` : 'user/emails'); export class UserEmails extends BaseResource { // Convenience method for create add( email: string, options?: { userId?: number; skipConfirmation?: boolean } & Sudo & ShowExpanded, ): Promise> { return this.create(email, options); } all({ userId, ...options }: { userId?: number } & Sudo & ShowExpanded = {}): Promise< GitlabAPIResponse > { return RequestHelper.get()( this, url(userId), options as Sudo & ShowExpanded, ); } create( email: string, { userId, ...options }: { userId?: number; skipConfirmation?: boolean } & Sudo & ShowExpanded = {}, ): Promise> { return RequestHelper.post()(this, url(userId), { email, ...options, }); } show( emailId: number, options?: Sudo & ShowExpanded, ): Promise> { return RequestHelper.get()(this, `user/emails/${emailId}`, options); } remove( emailId: number, { userId, ...options }: { userId?: number } & Sudo & ShowExpanded = {}, ): Promise> { return RequestHelper.del()( this, `${url(userId)}/${emailId}`, options as Sudo & ShowExpanded, ); } }