mirror of
https://github.com/jdalrymple/gitbeaker.git
synced 2026-01-25 16:04:01 +00:00
Adding extensive typing support Unified browser and Node.JS implementations Adding support of Gitlab API 16.0
66 lines
2.0 KiB
TypeScript
66 lines
2.0 KiB
TypeScript
import { BaseResource } from '@gitbeaker/requester-utils';
|
|
import { RequestHelper } from '../infrastructure';
|
|
import type { GitlabAPIResponse, ShowExpanded, Sudo } from '../infrastructure';
|
|
|
|
export interface UserEmailSchema extends Record<string, unknown> {
|
|
id: number;
|
|
email: string;
|
|
confirmed_at: string;
|
|
}
|
|
|
|
const url = (userId?: number) => (userId ? `users/${userId}/emails` : 'user/emails');
|
|
|
|
export class UserEmails<C extends boolean = false> extends BaseResource<C> {
|
|
// Convenience method for create
|
|
add<E extends boolean = false>(
|
|
email: string,
|
|
options?: { userId?: number; skipConfirmation?: boolean } & Sudo & ShowExpanded<E>,
|
|
): Promise<GitlabAPIResponse<UserEmailSchema, C, E, void>> {
|
|
return this.create<E>(email, options);
|
|
}
|
|
|
|
all<E extends boolean = false>({
|
|
userId,
|
|
...options
|
|
}: { userId?: number } & Sudo & ShowExpanded<E> = {}): Promise<
|
|
GitlabAPIResponse<UserEmailSchema[], C, E, void>
|
|
> {
|
|
return RequestHelper.get<UserEmailSchema[]>()(
|
|
this,
|
|
url(userId),
|
|
options as Sudo & ShowExpanded<E>,
|
|
);
|
|
}
|
|
|
|
create<E extends boolean = false>(
|
|
email: string,
|
|
{
|
|
userId,
|
|
...options
|
|
}: { userId?: number; skipConfirmation?: boolean } & Sudo & ShowExpanded<E> = {},
|
|
): Promise<GitlabAPIResponse<UserEmailSchema, C, E, void>> {
|
|
return RequestHelper.post<UserEmailSchema>()(this, url(userId), {
|
|
email,
|
|
...options,
|
|
});
|
|
}
|
|
|
|
show<E extends boolean = false>(
|
|
emailId: number,
|
|
options?: Sudo & ShowExpanded<E>,
|
|
): Promise<GitlabAPIResponse<UserEmailSchema, C, E, void>> {
|
|
return RequestHelper.get<UserEmailSchema>()(this, `user/emails/${emailId}`, options);
|
|
}
|
|
|
|
remove<E extends boolean = false>(
|
|
emailId: number,
|
|
{ userId, ...options }: { userId?: number } & Sudo & ShowExpanded<E> = {},
|
|
): Promise<GitlabAPIResponse<void, C, E, void>> {
|
|
return RequestHelper.del()(
|
|
this,
|
|
`${url(userId)}/${emailId}`,
|
|
options as Sudo & ShowExpanded<E>,
|
|
);
|
|
}
|
|
}
|