Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
2.8 kB
2
Indexable
Never
import { ResponseStatusEnum, RoleTypeEnum } from 'constant';
import { IAccount, IPartner } from 'types/model';
import axiosClient from './axiosInstance';

/**
 * Get List Account
 */

export interface GetListAccountPayload {
  locked?: boolean;
  username?: string;
  page?: number;
  size?: number;
}

export interface GetListAccountResponse {
  code: string;
  description: ResponseStatusEnum;
  data: {
    accountList: IAccount[];
    paging: {
      page: number;
      size: number;
      totalPage: number;
      totalRecord: number;
    };
  };
}

export const getAccounts = async (payload: GetListAccountPayload) => {
  const response = await axiosClient.get<GetListAccountResponse>('admin/account', {
    params: payload,
  });
  return response.data;
};

/**
 * Get Account By Id
 */

export interface GetAccountPayload {
  id: string;
}

export interface GetAccountResponse {
  code: string;
  description: ResponseStatusEnum;
  data: IAccount;
}

export const getAccount = async (payload: GetAccountPayload) => {
  const response = await axiosClient.get<GetAccountResponse>(`admin/account/${payload.id}`);
  return response.data;
};

/**
 * Create Account
 */

interface CreateAccountPayload {
  username: string;
  password: string;
  email: string;
  partnerId: string;
  role: RoleTypeEnum;
  locked?: boolean;
}

interface CreateAccountResponse {
  code: string;
  description: ResponseStatusEnum;
  data: any;
}

export const createAccount = async (payload: CreateAccountPayload) => {
  const response = await axiosClient.post<CreateAccountResponse>('admin/account', payload);
  return response.data;
};

/**
 * Update Account
 */

interface UpdateAccountPayload {
  id: string;
  username: string;
  partnerId: string;
  role: RoleTypeEnum;
  locked?: boolean;
}

interface UpdateAccountResponse {
  code: string;
  description: ResponseStatusEnum;
  data: any;
}

export const updateAccount = async (payload: UpdateAccountPayload) => {
  const response = await axiosClient.put<UpdateAccountResponse>(
    `admin/account/${payload.id}`,
    payload
  );
  return response.data;
};

/**
 * Delete Account
 */

export interface DeleteAccountPayload {
  id: string;
}

export interface DeleteAccountResponse {}

export const deleteAccount = async (payload: DeleteAccountPayload) => {
  const response = await axiosClient.delete<DeleteAccountResponse>(`admin/account/${payload.id}`);
  return response.data;
};

/**
 * Get List Partner
 */

export interface GetListPartnerPayload {}

export interface GetListPartnerResponse {
  code: string;
  description: ResponseStatusEnum;
  data: IPartner;
}

export const getPartners = async (payload: GetListPartnerPayload) => {
  const response = await axiosClient.get<GetListPartnerResponse>('admin/partner');
  return response.data;
};