All files / client/src/services userServices.ts

100% Statements 19/19
100% Branches 0/0
100% Functions 6/6
100% Lines 19/19

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96                                    356x     6x   6x               4x             356x 274x               271x     356x     9x               9x     356x       6x             6x       356x 8x     8x     356x     17x       9x    
import { api } from "client/utils/api";
import { ApiEndpoint } from "shared/constants/apiEndpoints";
import {
  GetSignupMessagesResponse,
  GetUserBySerialRequest,
  GetUserBySerialResponse,
  GetUserResponse,
  PostUpdateUserPasswordRequest,
  PostUpdateUserPasswordResponse,
  PostUserRequest,
  PostUserResponse,
} from "shared/types/api/users";
import { KonstiRegistrationFormFields } from "client/views/registration/components/KonstiRegistrationForm";
import {
  PostEventLogIsSeenRequest,
  PostEventLogIsSeenResponse,
} from "shared/types/api/eventLog";
 
export const postRegistration = async (
  registrationFormFields: KonstiRegistrationFormFields,
): Promise<PostUserResponse> => {
  const { username, password, serial } = registrationFormFields;
 
  const response = await api.post<PostUserResponse, PostUserRequest>(
    ApiEndpoint.USERS,
    {
      username,
      password,
      serial,
    },
  );
  return response.data;
};
 
interface GetUserParams {
  username: string;
}
 
export const getUser = async (username: string): Promise<GetUserResponse> => {
  const response = await api.get<GetUserResponse, GetUserParams>(
    ApiEndpoint.USERS,
    {
      params: {
        username,
      },
    },
  );
  return response.data;
};
 
export const getUserBySerialOrUsername = async (
  searchTerm: string,
): Promise<GetUserBySerialResponse> => {
  const response = await api.get<
    GetUserBySerialResponse,
    GetUserBySerialRequest
  >(ApiEndpoint.USERS_BY_SERIAL_OR_USERNAME, {
    params: {
      searchTerm,
    },
  });
  return response.data;
};
 
export const updateUserPassword = async (
  usernameToUpdate: string,
  password: string,
): Promise<PostUpdateUserPasswordResponse> => {
  const response = await api.post<
    PostUpdateUserPasswordResponse,
    PostUpdateUserPasswordRequest
  >(ApiEndpoint.USERS_PASSWORD, {
    usernameToUpdate,
    password,
  });
  return response.data;
};
 
export const getSignupMessages =
  async (): Promise<GetSignupMessagesResponse> => {
    const response = await api.get<GetSignupMessagesResponse>(
      ApiEndpoint.SIGNUP_MESSAGE,
    );
    return response.data;
  };
 
export const postEventLogItemIsSeen = async (
  request: PostEventLogIsSeenRequest,
): Promise<PostEventLogIsSeenResponse> => {
  const response = await api.post<
    PostEventLogIsSeenResponse,
    PostEventLogIsSeenRequest
  >(ApiEndpoint.EVENT_LOG_IS_SEEN, request);
  return response.data;
};