From 8cac908139c9b65516528cc8ac831e953bac9f3c Mon Sep 17 00:00:00 2001 From: raczu Date: Sat, 22 Jun 2024 19:09:40 +0200 Subject: [PATCH] feat: add services for handling request to API TODO: The endpoints for getting list of items needs to be updated after RSN-57. Addtionally, the structures for events endpoints should also be uploaded to be compliant with current state. --- Client/reasn-client/apps/web/lib/request.ts | 28 ++- Client/reasn-client/apps/web/package.json | 3 +- Client/reasn-client/apps/web/services/auth.ts | 34 ++++ .../reasn-client/apps/web/services/event.ts | 165 +++++++++++++++++ Client/reasn-client/apps/web/services/user.ts | 174 ++++++++++++++++++ .../__tests__/schemas/ParticipantDto.test.ts | 64 +++---- .../common/__tests__/schemas/UserDto.test.ts | 54 ++++++ .../common/src/schemas/ParticipantDto.ts | 4 +- .../packages/common/src/schemas/UserDto.ts | 2 + Client/reasn-client/yarn.lock | 10 +- 10 files changed, 492 insertions(+), 46 deletions(-) create mode 100644 Client/reasn-client/apps/web/services/auth.ts create mode 100644 Client/reasn-client/apps/web/services/event.ts create mode 100644 Client/reasn-client/apps/web/services/user.ts diff --git a/Client/reasn-client/apps/web/lib/request.ts b/Client/reasn-client/apps/web/lib/request.ts index 50af1c70..05c26ba1 100644 --- a/Client/reasn-client/apps/web/lib/request.ts +++ b/Client/reasn-client/apps/web/lib/request.ts @@ -18,11 +18,15 @@ export type ProblemDetails = { instance?: string; }; +export type RequestOptions = { + method: HttpMethod; + body?: Object | FormData; + authRequired?: boolean; +}; + export const sendRequest = async ( - url: string, - httpMethod: HttpMethod, - body: Object = {}, - authRequired: boolean = false, + url: string | URL, + { method, body = {}, authRequired = false }: RequestOptions, ): Promise => { try { let headers: HeadersInit = new Headers(); @@ -37,13 +41,17 @@ export const sendRequest = async ( } const fetchOptions: RequestInit = { - method: httpMethod, + method: method, headers, }; - if (httpMethod == HttpMethod.POST || httpMethod == HttpMethod.PUT) { - headers.set("Content-Type", "application/json"); - fetchOptions.body = JSON.stringify(body); + if (method == HttpMethod.POST || method == HttpMethod.PUT) { + if (body instanceof FormData) { + fetchOptions.body = body; + } else { + headers.set("Content-Type", "application/json"); + fetchOptions.body = JSON.stringify(body); + } } const response = await fetch(url, fetchOptions); @@ -61,10 +69,10 @@ export const sendRequest = async ( ); } - return (await response.json()) as T; + return response.json().catch(() => {}) as T; } catch (error) { console.error( - `Error while sending request to ${url} with method ${httpMethod}: ${error}`, + `Error while sending request to ${url} with method ${method}: ${error}`, ); throw Error; } diff --git a/Client/reasn-client/apps/web/package.json b/Client/reasn-client/apps/web/package.json index 12e15618..7fdb9811 100644 --- a/Client/reasn-client/apps/web/package.json +++ b/Client/reasn-client/apps/web/package.json @@ -11,8 +11,9 @@ "dependencies": { "@reasn/common": "*", "@reasn/ui": "*", + "@types/url-search-params": "^1.1.2", "jwt-decode": "^4.0.0", - "next": "^14.0.4", + "next": "^14.1.1", "react": "^18.2.0", "react-dom": "^18.2.0", "react-native-web": "^0.19.10" diff --git a/Client/reasn-client/apps/web/services/auth.ts b/Client/reasn-client/apps/web/services/auth.ts new file mode 100644 index 00000000..bc20bf6b --- /dev/null +++ b/Client/reasn-client/apps/web/services/auth.ts @@ -0,0 +1,34 @@ +import { sendRequest, HttpMethod } from "@/lib/request"; +import { + TokenPayload, + TokenPayloadMapper, +} from "@reasn/common/src/schemas/TokenPayload"; +import { LoginRequest } from "@reasn/common/src/schemas/LoginRequest"; +import { RegisterRequest } from "@reasn/common/src/schemas/RegisterRequest"; +import { UserDto, UserDtoMapper } from "@reasn/common/src/schemas/UserDto"; + +const baseUrl = `${process.env.REASN_API_URL}/api/v1/auth`; + +export const login = async ( + loginRequest: LoginRequest, +): Promise => { + const url = new URL(`${baseUrl}/login`); + + const response = await sendRequest(url, { + method: HttpMethod.POST, + body: loginRequest, + }); + return TokenPayloadMapper.fromObject(response); +}; + +export const register = async ( + registerRequest: RegisterRequest, +): Promise => { + const url = new URL(`${baseUrl}/register`); + + const response = await sendRequest(url, { + method: HttpMethod.POST, + body: registerRequest, + }); + return UserDtoMapper.fromObject(response); +}; diff --git a/Client/reasn-client/apps/web/services/event.ts b/Client/reasn-client/apps/web/services/event.ts new file mode 100644 index 00000000..4a77415f --- /dev/null +++ b/Client/reasn-client/apps/web/services/event.ts @@ -0,0 +1,165 @@ +import { sendRequest, HttpMethod } from "@/lib/request"; + +const baseUrl = `${process.env.REASN_API_URL}/api/v1/events`; + +export const getEvents = async ( + params: Record = {}, +): Promise => { + const url = new URL(baseUrl); + url.search = new URLSearchParams(params).toString(); + + const response = await sendRequest(url, { method: HttpMethod.GET }); + return response; +}; + +export const createEvent = async (event: any): Promise => { + const url = new URL(baseUrl); + + const response = await sendRequest(url, { + method: HttpMethod.POST, + body: event, + authRequired: true, + }); + return response; +}; + +export const getEventBySlug = async (slug: string): Promise => { + const url = new URL(`${baseUrl}/${slug}`); + + const response = await sendRequest(url, { method: HttpMethod.GET }); + return response; +}; + +export const updateEvent = async (slug: string, event: any): Promise => { + const url = new URL(`${baseUrl}/${slug}`); + + const response = await sendRequest(url, { + method: HttpMethod.PUT, + body: event, + authRequired: true, + }); + return response; +}; + +export const getEventsRequests = async (): Promise => { + const url = new URL(`${baseUrl}/requests`); + + const response = await sendRequest(url, { + method: HttpMethod.GET, + authRequired: true, + }); + return response; +}; + +export const approveEventRequest = async (slug: string): Promise => { + const url = new URL(`${baseUrl}/requests/${slug}`); + + const response = await sendRequest(url, { + method: HttpMethod.POST, + authRequired: true, + }); + return response; +}; + +export const addEventImage = async ( + slug: string, + images: Blob[], +): Promise => { + const url = new URL(`${baseUrl}/${slug}/images`); + + const formData = new FormData(); + images.forEach((image) => { + formData.append("images", image); + }); + + const response = await sendRequest(url, { + method: HttpMethod.POST, + body: formData, + authRequired: true, + }); + return response; +}; + +export const updateEventImage = async ( + slug: string, + images: Blob[], +): Promise => { + const url = new URL(`${baseUrl}/${slug}/images`); + + const formData = new FormData(); + images.forEach((image) => { + formData.append("images", image); + }); + + const response = await sendRequest(url, { + method: HttpMethod.PUT, + body: formData, + authRequired: true, + }); + return response; +}; + +export const getEventImages = async (slug: string): Promise => { + const url = new URL(`${baseUrl}/${slug}/images`); + + const response = await sendRequest(url, { method: HttpMethod.GET }); + return response; +}; + +export const getEventParticipants = async (slug: string): Promise => { + const url = new URL(`${baseUrl}/${slug}/participants`); + + const response = await sendRequest(url, { method: HttpMethod.GET }); + return response; +}; + +export const getEventComments = async (slug: string): Promise => { + const url = new URL(`${baseUrl}/${slug}/comments`); + + const response = await sendRequest(url, { method: HttpMethod.GET }); + return response; +}; + +export const addEventComment = async ( + slug: string, + comment: any, +): Promise => { + const url = new URL(`${baseUrl}/${slug}/comments`); + + const response = await sendRequest(url, { + method: HttpMethod.POST, + body: comment, + authRequired: true, + }); + return response; +}; + +export const getEventsParameters = async (): Promise => { + const url = new URL(`${baseUrl}/parameters`); + + const response = await sendRequest(url, { + method: HttpMethod.GET, + authRequired: true, + }); + return response; +}; + +export const getEventsTags = async (): Promise => { + const url = new URL(`${baseUrl}/tags`); + + const response = await sendRequest(url, { + method: HttpMethod.GET, + authRequired: true, + }); + return response; +}; + +export const deleteEventsTag = async (tagId: number): Promise => { + const url = new URL(`${baseUrl}/tags/${tagId}`); + + const response = await sendRequest(url, { + method: HttpMethod.DELETE, + authRequired: true, + }); + return response; +}; diff --git a/Client/reasn-client/apps/web/services/user.ts b/Client/reasn-client/apps/web/services/user.ts new file mode 100644 index 00000000..80badc15 --- /dev/null +++ b/Client/reasn-client/apps/web/services/user.ts @@ -0,0 +1,174 @@ +import { sendRequest, HttpMethod } from "@/lib/request"; +import { UserDto, UserDtoMapper } from "@reasn/common/src/schemas/UserDto"; +import { + ParticipantDto, + ParticipantDtoMapper, +} from "@reasn/common/src/schemas/ParticipantDto"; + +const baseUrl = `${process.env.REASN_API_URL}/api/v1`; +const baseUsersUrl = `${baseUrl}/users`; +const baseMeUrl = `${baseUrl}/me`; + +export const getUsers = async ( + params: Record = {}, +): Promise => { + const url = new URL(baseUsersUrl); + url.search = new URLSearchParams(params).toString(); + + const response = await sendRequest(url, { + method: HttpMethod.GET, + authRequired: true, + }); + return response; +}; + +export const getUserByUsername = async (username: string): Promise => { + const url = new URL(`${baseUsersUrl}/${username}`); + + const response = await sendRequest(url, { method: HttpMethod.GET }); + return UserDtoMapper.fromObject(response); +}; + +export const updateUser = async ( + username: string, + user: UserDto, +): Promise => { + const url = new URL(`${baseUsersUrl}/${username}`); + + const response = await sendRequest(url, { + method: HttpMethod.PUT, + body: user, + authRequired: true, + }); + return UserDtoMapper.fromObject(response); +}; + +export const getUsersInterests = async ( + params: Record = {}, +): Promise => { + const url = new URL(`${baseUsersUrl}/interests`); + url.search = new URLSearchParams(params).toString(); + + const response = await sendRequest(url, { method: HttpMethod.GET }); + return response; +}; + +export const deleteUserInterest = async ( + insterestId: number, +): Promise => { + const url = new URL(`${baseUsersUrl}/interests/${insterestId}`); + + const response = await sendRequest(url, { + method: HttpMethod.DELETE, + authRequired: true, + }); + return response; +}; + +export const getCurrentUser = async (): Promise => { + const url = new URL(baseMeUrl); + + const response = await sendRequest(url, { + method: HttpMethod.GET, + authRequired: true, + }); + return UserDtoMapper.fromObject(response); +}; + +export const updateCurrentUser = async (user: UserDto): Promise => { + const url = new URL(baseMeUrl); + + const response = await sendRequest(url, { + method: HttpMethod.PUT, + body: user, + authRequired: true, + }); + return UserDtoMapper.fromObject(response); +}; + +export const addCurrentUserImage = async (image: Blob): Promise => { + const url = new URL(`${baseMeUrl}/image`); + + const formData = new FormData(); + formData.append("images", image); + + const response = await sendRequest(url, { + method: HttpMethod.POST, + body: formData, + authRequired: true, + }); + return response; +}; + +export const updateCurrentUserImage = async (image: Blob): Promise => { + const url = new URL(`${baseMeUrl}/image`); + + const formData = new FormData(); + formData.append("images", image); + + const response = await sendRequest(url, { + method: HttpMethod.PUT, + body: formData, + authRequired: true, + }); + return response; +}; + +export const deleteCurrentUserImage = async (): Promise => { + const url = new URL(`${baseMeUrl}/image`); + + const response = await sendRequest(url, { + method: HttpMethod.DELETE, + authRequired: true, + }); + return response; +}; + +export const getCurrentUserEvents = async ( + params: Record = {}, +): Promise => { + const url = new URL(`${baseMeUrl}/events`); + url.search = new URLSearchParams(params).toString(); + + const response = await sendRequest(url, { + method: HttpMethod.GET, + authRequired: true, + }); + return response; +}; + +export const enrollCurrentUserInEvent = async ( + slug: string, +): Promise => { + const url = new URL(`${baseMeUrl}/events/${slug}/enroll`); + + const response = await sendRequest(url, { + method: HttpMethod.POST, + authRequired: true, + }); + return ParticipantDtoMapper.fromObject(response); +}; + +export const confirmCurrentUserAttendace = async ( + slug: string, +): Promise => { + const url = new URL(`${baseMeUrl}/events/${slug}/confirm`); + + const response = await sendRequest(url, { + method: HttpMethod.POST, + authRequired: true, + }); + return ParticipantDtoMapper.fromObject(response); +}; + +export const cancelCurrentUserAttendance = async ( + slug: string, +): Promise => { + const url = new URL(`${baseMeUrl}/events/${slug}/cancel`); + + const response = await sendRequest(url, { + method: HttpMethod.POST, + authRequired: true, + }); + return ParticipantDtoMapper.fromObject(response); +}; diff --git a/Client/reasn-client/packages/common/__tests__/schemas/ParticipantDto.test.ts b/Client/reasn-client/packages/common/__tests__/schemas/ParticipantDto.test.ts index b597fb9d..f70347c9 100644 --- a/Client/reasn-client/packages/common/__tests__/schemas/ParticipantDto.test.ts +++ b/Client/reasn-client/packages/common/__tests__/schemas/ParticipantDto.test.ts @@ -6,23 +6,23 @@ import { import { ParticipantStatus } from "@reasn/common/src/enums/modelsEnums"; describe("ParticipantDto", () => { - const eventId = 1; - const userId = 2; + const eventSlug = "event-slug"; + const username = "username"; const status = ParticipantStatus.INTERESTED; describe("fromJson", () => { it("should create an instance of ParticipantDto from JSON string", () => { const json = `{ - "EventId": ${eventId}, - "UserId": ${userId}, + "EventSlug": "${eventSlug}", + "Username": "${username}", "Status": "${status}" }`; let participant = ParticipantDtoMapper.fromJSON(json); participant = participant as ParticipantDto; - expect(participant.EventId).toBe(eventId); - expect(participant.UserId).toBe(userId); + expect(participant.EventSlug).toBe(eventSlug); + expect(participant.Username).toBe(username); expect(participant.Status).toBe(status); }); @@ -33,28 +33,28 @@ describe("ParticipantDto", () => { }); it("should throw an error when providing JSON without each property individually", () => { - const jsonWithoutEventId = `{ - "UserId": ${userId}, + const jsonWithoutEventSlug = `{ + "Username": "${username}", "Status": "${status}" }`; - const jsonWithoutUserId = `{ - "EventId": ${eventId}, + const jsonWithoutUsername = `{ + "EventSlug": "${eventSlug}", "Status": "${status}" }`; - const jsonWithoutStatusId = `{ - "EventId": ${eventId}, - "UserId": ${userId} + const jsonWithoutStatus = `{ + "EventSlug": "${eventSlug}", + "Username": "${username}" }`; - expect(() => ParticipantDtoMapper.fromJSON(jsonWithoutEventId)).toThrow( + expect(() => ParticipantDtoMapper.fromJSON(jsonWithoutEventSlug)).toThrow( ModelMappingError, ); - expect(() => ParticipantDtoMapper.fromJSON(jsonWithoutUserId)).toThrow( + expect(() => ParticipantDtoMapper.fromJSON(jsonWithoutUsername)).toThrow( ModelMappingError, ); - expect(() => ParticipantDtoMapper.fromJSON(jsonWithoutStatusId)).toThrow( + expect(() => ParticipantDtoMapper.fromJSON(jsonWithoutStatus)).toThrow( ModelMappingError, ); }); @@ -63,52 +63,52 @@ describe("ParticipantDto", () => { describe("fromObject", () => { it("should create an instance of ParticipantDto from an object", () => { const object = { - EventId: eventId, - UserId: userId, + EventSlug: eventSlug, + Username: username, Status: status, }; let participant = ParticipantDtoMapper.fromObject(object); participant = participant as ParticipantDto; - expect(participant.EventId).toBe(eventId); - expect(participant.UserId).toBe(userId); + expect(participant.EventSlug).toBe(eventSlug); + expect(participant.Username).toBe(username); expect(participant.Status).toBe(status); }); it("should throw an error if the object is invalid", () => { const object = { - EventId: true, - UserId: null, + EventStatus: true, + Username: null, Status: "invalid", }; - const objectWithoutEventId = { - UserId: userId, + const objectWithoutEventSlug = { + Username: username, Status: status, }; - const objectWithoutUserId = { - EventId: eventId, + const objectWithoutUsername = { + EventSlug: eventSlug, Status: status, }; - const objectWithoutStatusId = { - EventId: eventId, - UserId: userId, + const objectWithoutStatus = { + EventSlug: eventSlug, + Username: username, }; expect(() => ParticipantDtoMapper.fromObject(object)).toThrow( ModelMappingError, ); expect(() => - ParticipantDtoMapper.fromObject(objectWithoutEventId), + ParticipantDtoMapper.fromObject(objectWithoutEventSlug), ).toThrow(ModelMappingError); expect(() => - ParticipantDtoMapper.fromObject(objectWithoutUserId), + ParticipantDtoMapper.fromObject(objectWithoutUsername), ).toThrow(ModelMappingError); expect(() => - ParticipantDtoMapper.fromObject(objectWithoutStatusId), + ParticipantDtoMapper.fromObject(objectWithoutStatus), ).toThrow(ModelMappingError); }); }); diff --git a/Client/reasn-client/packages/common/__tests__/schemas/UserDto.test.ts b/Client/reasn-client/packages/common/__tests__/schemas/UserDto.test.ts index 4b2d185c..a08b06c7 100644 --- a/Client/reasn-client/packages/common/__tests__/schemas/UserDto.test.ts +++ b/Client/reasn-client/packages/common/__tests__/schemas/UserDto.test.ts @@ -2,6 +2,7 @@ import ModelMappingError from "@reasn/common/src/errors/ModelMappingError"; import { UserDto, UserDtoMapper } from "@reasn/common/src/schemas/UserDto"; import { UserInterestDto } from "@reasn/common/src/schemas/UserInterestDto"; import { UserRole } from "@reasn/common/src/enums/modelsEnums"; +import { AddressDto } from "@reasn/common/src/schemas/AddressDto"; describe("UserDto", () => { const username = "john_doe"; @@ -11,6 +12,13 @@ describe("UserDto", () => { const phone = "+48 1234567890"; const role = UserRole.USER; const addressId = 2; + const address: AddressDto = { + Country: "Test Country", + City: "Test City", + Street: "Test Street", + State: "Test State", + ZipCode: "12345", + }; const interests: UserInterestDto[] = [ { Interest: { Name: "Programming" }, Level: 5 }, { Interest: { Name: "Music" }, Level: 3 }, @@ -26,6 +34,7 @@ describe("UserDto", () => { "Phone": "${phone}", "Role": "${role}", "AddressId": ${addressId}, + "Address": ${JSON.stringify(address)}, "Intrests": ${JSON.stringify(interests)} }`; @@ -39,6 +48,7 @@ describe("UserDto", () => { expect(user.Phone).toBe(phone); expect(user.Role).toBe(role); expect(user.AddressId).toBe(addressId); + expect(user.Address).toEqual(address); expect(user.Intrests).toEqual(interests); }); @@ -54,6 +64,7 @@ describe("UserDto", () => { "Phone": "${phone}", "Role": "${role}", "AddressId": ${addressId}, + "Address": ${JSON.stringify(address)}, "Intrests": ${JSON.stringify(interests)} }`; @@ -64,6 +75,7 @@ describe("UserDto", () => { "Phone": "${phone}", "Role": "${role}", "AddressId": ${addressId}, + "Address": ${JSON.stringify(address)}, "Intrests": ${JSON.stringify(interests)} }`; @@ -74,6 +86,7 @@ describe("UserDto", () => { "Phone": "${phone}", "Role": "${role}", "AddressId": ${addressId}, + "Address": ${JSON.stringify(address)}, "Intrests": ${JSON.stringify(interests)} }`; @@ -84,6 +97,7 @@ describe("UserDto", () => { "Phone": "${phone}", "Role": "${role}", "AddressId": ${addressId}, + "Address": ${JSON.stringify(address)}, "Intrests": ${JSON.stringify(interests)} }`; @@ -104,6 +118,7 @@ describe("UserDto", () => { "Email": "${email}", "Phone": "${phone}", "AddressId": ${addressId}, + "Address": ${JSON.stringify(address)}, "Intrests": ${JSON.stringify(interests)} }`; @@ -114,9 +129,21 @@ describe("UserDto", () => { "Email": "${email}", "Phone": "${phone}", "Role": "${role}", + "Address": ${JSON.stringify(address)}, "Intrests": ${JSON.stringify(interests)} }`; + const jsonWithoutAddress = `{ + "Username": "${username}", + "Name": "${name}", + "Surname": "${surname}", + "Email": "${email}", + "Phone": "${phone}", + "AddressId": ${addressId}, + "Role": "${role}", + "Intrests": ${JSON.stringify(interests)} + }`; + const jsonWithoutInterests = `{ "Username": "${username}", "Name": "${name}", @@ -148,6 +175,9 @@ describe("UserDto", () => { expect(() => UserDtoMapper.fromJSON(jsonWithoutAddressId)).toThrow( ModelMappingError, ); + expect(() => UserDtoMapper.fromJSON(jsonWithoutAddress)).toThrow( + ModelMappingError, + ); expect(() => UserDtoMapper.fromJSON(jsonWithoutInterests)).toThrow( ModelMappingError, ); @@ -164,6 +194,7 @@ describe("UserDto", () => { Phone: phone, Role: role, AddressId: addressId, + Address: address, Intrests: interests, }; @@ -177,6 +208,7 @@ describe("UserDto", () => { expect(user.Phone).toBe(phone); expect(user.Role).toBe(role); expect(user.AddressId).toBe(addressId); + expect(user.Address).toEqual(address); expect(user.Intrests).toEqual(interests); }); @@ -199,6 +231,7 @@ describe("UserDto", () => { Phone: phone, Role: role, AddressId: addressId, + Address: address, Intrests: interests, }; @@ -209,6 +242,7 @@ describe("UserDto", () => { Phone: phone, Role: role, AddressId: addressId, + Address: address, Intrests: interests, }; @@ -219,6 +253,7 @@ describe("UserDto", () => { Phone: phone, Role: role, AddressId: addressId, + Address: address, Intrests: interests, }; @@ -229,6 +264,7 @@ describe("UserDto", () => { Phone: phone, Role: role, AddressId: addressId, + Address: address, Intrests: interests, }; @@ -239,6 +275,7 @@ describe("UserDto", () => { Email: email, Role: role, AddressId: addressId, + Address: address, Intrests: interests, }; @@ -249,6 +286,7 @@ describe("UserDto", () => { Email: email, Phone: phone, AddressId: addressId, + Address: address, Intrests: interests, }; @@ -259,6 +297,18 @@ describe("UserDto", () => { Email: email, Phone: phone, Role: role, + Address: address, + Intrests: interests, + }; + + const objectWithoutAddress = { + Username: username, + Name: name, + Surname: surname, + Email: email, + Phone: phone, + Role: role, + AddressId: addressId, Intrests: interests, }; @@ -270,6 +320,7 @@ describe("UserDto", () => { Phone: phone, Role: role, AddressId: addressId, + Address: address, }; expect(() => UserDtoMapper.fromObject(object)).toThrow(ModelMappingError); @@ -294,6 +345,9 @@ describe("UserDto", () => { expect(() => UserDtoMapper.fromObject(objectWithoutAddressId)).toThrow( ModelMappingError, ); + expect(() => UserDtoMapper.fromObject(objectWithoutAddress)).toThrow( + ModelMappingError, + ); expect(() => UserDtoMapper.fromObject(objectWithoutInterests)).toThrow( ModelMappingError, ); diff --git a/Client/reasn-client/packages/common/src/schemas/ParticipantDto.ts b/Client/reasn-client/packages/common/src/schemas/ParticipantDto.ts index 7d81423b..63d6e21f 100644 --- a/Client/reasn-client/packages/common/src/schemas/ParticipantDto.ts +++ b/Client/reasn-client/packages/common/src/schemas/ParticipantDto.ts @@ -3,8 +3,8 @@ import { ParticipantStatus } from "../enums/modelsEnums"; import { z } from "zod"; export const ParticipantDtoSchema = z.object({ - EventId: z.number(), - UserId: z.number(), + EventSlug: z.string(), + Username: z.string(), Status: z.nativeEnum(ParticipantStatus), }); diff --git a/Client/reasn-client/packages/common/src/schemas/UserDto.ts b/Client/reasn-client/packages/common/src/schemas/UserDto.ts index 16b0f673..e4faa534 100644 --- a/Client/reasn-client/packages/common/src/schemas/UserDto.ts +++ b/Client/reasn-client/packages/common/src/schemas/UserDto.ts @@ -1,5 +1,6 @@ import ModelMappingError from "../errors/ModelMappingError"; import { UserInterestDtoSchema } from "../schemas/UserInterestDto"; +import { AddressDtoSchema } from "../schemas/AddressDto"; import { UserRole } from "../enums/modelsEnums"; import { z } from "zod"; @@ -23,6 +24,7 @@ export const UserDtoSchema = z.object({ .refine((value) => value === null || /^\+\d{1,3}\s\d{1,15}$/.test(value)), Role: z.nativeEnum(UserRole), AddressId: z.number(), + Address: AddressDtoSchema, Intrests: z.array(UserInterestDtoSchema), }); diff --git a/Client/reasn-client/yarn.lock b/Client/reasn-client/yarn.lock index e2807b40..1326e348 100644 --- a/Client/reasn-client/yarn.lock +++ b/Client/reasn-client/yarn.lock @@ -4770,6 +4770,13 @@ __metadata: languageName: node linkType: hard +"@types/url-search-params@npm:^1.1.2": + version: 1.1.2 + resolution: "@types/url-search-params@npm:1.1.2" + checksum: 10c0/3575548b8d94b7f4509fc1645d4c32d75c12a180ed86a67d3521f730fcdddba67de9e43d282ff22d00cddf2dbc1dbb91b3e3cda698fdf3acd697c5124ebecd3e + languageName: node + linkType: hard + "@types/ws@npm:^8.5.5": version: 8.5.10 resolution: "@types/ws@npm:8.5.10" @@ -17471,12 +17478,13 @@ __metadata: "@types/node": "npm:^20.10.6" "@types/react": "npm:^18.2.46" "@types/react-dom": "npm:^18.2.18" + "@types/url-search-params": "npm:^1.1.2" babel-plugin-react-native-web: "npm:^0.19.10" eslint: "npm:^8.57.0" eslint-config-next: "npm:14.0.4" eslint-config-prettier: "npm:^9.1.0" jwt-decode: "npm:^4.0.0" - next: "npm:^14.0.4" + next: "npm:^14.1.1" react: "npm:^18.2.0" react-dom: "npm:^18.2.0" react-native-web: "npm:^0.19.10"