Skip to content

Commit

Permalink
feat: user endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
remcohendriks authored and myparcel-bot[bot] committed Apr 16, 2024
1 parent 4d435b3 commit 741463a
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/__snapshots__/index.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ exports[`module exports > exposes the correct data from index.ts 1`] = `
"GetSystemCountryCodes": [Function],
"GetSystemMessages": [Function],
"GetTrackAndTrace": [Function],
"GetUser": [Function],
"GetUsers": [Function],
"GetWebhookSubscriptions": [Function],
"PatchSubscriptions": [Function],
"PostApiKeys": [Function],
Expand Down
3 changes: 2 additions & 1 deletion src/endpoints/private/accounts/Account.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {type PlatformId} from '@myparcel/constants';
import {type Address} from '@/types/common.types';
import {type PaginationParameters, type IntBoolean, type Price} from '@/types';
import {type MyParcelShop} from '@/endpoints/private/shops/Shop.types';
import {type User} from '@/endpoints/private/users/User.types';

export interface AccountAdditionalInfo {
ecommerce_platform: string;
Expand Down Expand Up @@ -52,7 +53,7 @@ export interface MyParcelAccount {
status: AccountStatus;
terms_agreed: boolean;
username: string;
users: Record<string, unknown>;
users: User[];
}

export type GetAccountsParams = PaginationParameters & {
Expand Down
1 change: 1 addition & 0 deletions src/endpoints/private/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export * from './subscriptions';
export * from './system-country-codes';
export * from './system-messages';
export * from './track-traces';
export * from './users';
export * from './webhook-subscriptions';
17 changes: 17 additions & 0 deletions src/endpoints/private/users/GetUser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {AbstractPrivateEndpoint} from '@/model/endpoint/AbstractPrivateEndpoint';
import type {CreateDefinition} from '@/model/endpoint/AbstractEndpoint.types';
import type {User} from './User.types';

type GetUserDefinition = CreateDefinition<{
name: typeof GetUser.name;
response: User[];
}>;

/**
* Retrieve single user by id. The endpoint can be called with multiple ids, separated by semicolon.
*/
export class GetUser extends AbstractPrivateEndpoint<GetUserDefinition> {
public readonly name = 'getUser';
public readonly path = 'users/:id';
public readonly property = 'users';
}
20 changes: 20 additions & 0 deletions src/endpoints/private/users/GetUsers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {type CreateDefinition, PaginatedResponse} from '@/model/endpoint/AbstractEndpoint.types';
import {AbstractPrivateEndpoint} from '@/model/endpoint/AbstractPrivateEndpoint';
import type {PaginationParameters} from '@/types';
import type {User} from './User.types';

type GetUserDefinition = CreateDefinition<{
name: typeof GetUsers.name;
parameters: PaginationParameters;
response: PaginatedResponse<User[]>;
}>;

/**
* Retrieve users. Accepts pagination parameters.
*/
export class GetUsers extends AbstractPrivateEndpoint<GetUserDefinition> {
public readonly name = 'getUsers';
public readonly path = 'users';
public readonly property = 'users';
}

38 changes: 38 additions & 0 deletions src/endpoints/private/users/User.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
export interface User {
id: number;
account_id: number;
username: string;
created: string;
remember_token: string | null;
all_shop_access: boolean;
sortPayload: number[];
contact: Contact;
roles: Role[];
}

interface Contact {
id: number;
gender: string;
first_name: string;
last_name: string;
email: string;
phone: string | null;
company: string | null;
street: string;
number: string;
number_suffix: string;
box_number: string;
postal_code: string;
city: string;
cc: string | null;
street_additional_info: string;
region: string;
}

interface Role {
id: number;
description: string;
name: string;
role_type: string;
}

Check warning on line 37 in src/endpoints/private/users/User.types.ts

View check run for this annotation

Codecov / codecov/patch

src/endpoints/private/users/User.types.ts#L2-L37

Added lines #L2 - L37 were not covered by tests

2 changes: 2 additions & 0 deletions src/endpoints/private/users/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './GetUser';
export * from './GetUsers';

0 comments on commit 741463a

Please sign in to comment.