From e51b93c32af303cb828cda674b78f3bac430268b Mon Sep 17 00:00:00 2001 From: Dawid Machoczek Date: Sun, 23 Jun 2024 17:32:28 +0200 Subject: [PATCH] [RSN-86] Make frontend schemas compliant with backend requests/responses (#75) * refactor: make schemas compliant with backend models * refactor: add appropriate return types in services --- .../reasn-client/apps/web/services/event.ts | 7 +- Client/reasn-client/apps/web/services/user.ts | 7 +- .../__tests__/schemas/CommentDto.test.ts | 193 +++++--- .../common/__tests__/schemas/EventDto.test.ts | 463 ------------------ .../common/__tests__/schemas/ImageDto.test.ts | 110 ----- .../__tests__/schemas/InterestDto.test.ts | 8 +- .../__tests__/schemas/ParameterDto.test.ts | 28 +- .../__tests__/schemas/ParticipantDto.test.ts | 54 +- .../common/__tests__/schemas/TagDto.test.ts | 10 +- .../common/__tests__/schemas/UserDto.test.ts | 4 +- .../__tests__/schemas/UserInterestDto.test.ts | 30 +- .../packages/common/src/schemas/CommentDto.ts | 15 +- .../common/src/schemas/CommentRequest.ts | 7 + .../packages/common/src/schemas/EventDto.ts | 73 --- .../common/src/schemas/EventResponse.ts | 15 +- .../packages/common/src/schemas/ImageDto.ts | 39 -- .../common/src/schemas/InterestDto.ts | 2 +- .../common/src/schemas/ParameterDto.ts | 4 +- .../common/src/schemas/ParticipantDto.ts | 6 +- .../packages/common/src/schemas/TagDto.ts | 2 +- .../common/src/schemas/UserInterestDto.ts | 4 +- 21 files changed, 229 insertions(+), 852 deletions(-) delete mode 100644 Client/reasn-client/packages/common/__tests__/schemas/EventDto.test.ts delete mode 100644 Client/reasn-client/packages/common/__tests__/schemas/ImageDto.test.ts create mode 100644 Client/reasn-client/packages/common/src/schemas/CommentRequest.ts delete mode 100644 Client/reasn-client/packages/common/src/schemas/EventDto.ts delete mode 100644 Client/reasn-client/packages/common/src/schemas/ImageDto.ts diff --git a/Client/reasn-client/apps/web/services/event.ts b/Client/reasn-client/apps/web/services/event.ts index ea052b4b..29ebccc7 100644 --- a/Client/reasn-client/apps/web/services/event.ts +++ b/Client/reasn-client/apps/web/services/event.ts @@ -6,6 +6,7 @@ import { } from "@reasn/common/src/schemas/EventResponse"; import { ParameterDto } from "@reasn/common/src/schemas/ParameterDto"; import { TagDto } from "@reasn/common/src/schemas/TagDto"; +import { CommentDto } from "@reasn/common/src/schemas/CommentDto"; const baseUrl = `${process.env.REASN_API_URL}/api/v1/events`; @@ -129,10 +130,12 @@ export const getEventParticipants = async (slug: string): Promise => { return response; }; -export const getEventComments = async (slug: string): Promise => { +export const getEventComments = async (slug: string): Promise => { const url = new URL(`${baseUrl}/${slug}/comments`); - const response = await sendRequest(url, { method: HttpMethod.GET }); + const response = await sendRequest(url, { + method: HttpMethod.GET, + }); return response; }; diff --git a/Client/reasn-client/apps/web/services/user.ts b/Client/reasn-client/apps/web/services/user.ts index 80badc15..a16d736e 100644 --- a/Client/reasn-client/apps/web/services/user.ts +++ b/Client/reasn-client/apps/web/services/user.ts @@ -4,6 +4,7 @@ import { ParticipantDto, ParticipantDtoMapper, } from "@reasn/common/src/schemas/ParticipantDto"; +import { InterestDto } from "@reasn/common/src/schemas/InterestDto"; const baseUrl = `${process.env.REASN_API_URL}/api/v1`; const baseUsersUrl = `${baseUrl}/users`; @@ -45,11 +46,13 @@ export const updateUser = async ( export const getUsersInterests = async ( params: Record = {}, -): Promise => { +): Promise => { const url = new URL(`${baseUsersUrl}/interests`); url.search = new URLSearchParams(params).toString(); - const response = await sendRequest(url, { method: HttpMethod.GET }); + const response = await sendRequest(url, { + method: HttpMethod.GET, + }); return response; }; diff --git a/Client/reasn-client/packages/common/__tests__/schemas/CommentDto.test.ts b/Client/reasn-client/packages/common/__tests__/schemas/CommentDto.test.ts index 20645b92..9aba26a1 100644 --- a/Client/reasn-client/packages/common/__tests__/schemas/CommentDto.test.ts +++ b/Client/reasn-client/packages/common/__tests__/schemas/CommentDto.test.ts @@ -5,27 +5,30 @@ import { } from "@reasn/common/src/schemas/CommentDto"; describe("CommentDto", () => { - const eventId = 1; + const eventSlug = "event-slug"; const content = "Test Content"; const createdAt = new Date(); - const userId = 2; + const username = "username"; + const userImageUrl = "url"; describe("fromJson", () => { it("should create an instance of CommentDto from JSON string", () => { const json = `{ - "EventId": ${eventId}, - "Content": "${content}", - "CreatedAt": "${createdAt.toISOString()}", - "UserId": ${userId} + "eventSlug": "${eventSlug}", + "content": "${content}", + "createdAt": "${createdAt.toISOString()}", + "username": "${username}", + "userImageUrl": "${userImageUrl}" }`; let comment = CommentDtoMapper.fromJSON(json); comment = comment as CommentDto; - expect(comment.EventId).toBe(eventId); - expect(comment.Content).toBe(content); - expect(comment.CreatedAt).toEqual(createdAt); - expect(comment.UserId).toBe(userId); + expect(comment.eventSlug).toBe(eventSlug); + expect(comment.content).toBe(content); + expect(comment.createdAt).toEqual(createdAt); + expect(comment.username).toBe(username); + expect(comment.userImageUrl).toBe(userImageUrl); }); it("should throw an error if the JSON string is empty", () => { @@ -33,31 +36,42 @@ describe("CommentDto", () => { }); it("should throw an error when providing JSON without each property individually", () => { - const jsonWithoutEventId = `{ - "Content": "${content}", - "CreatedAt": "${createdAt.toISOString()}", - "UserId": ${userId} + const jsonWithoutEventSlug = `{ + "content": "${content}", + "createdAt": "${createdAt.toISOString()}", + "username": "${username}", + "userImageUrl": "${userImageUrl}" }`; const jsonWithoutContent = `{ - "EventId": ${eventId}, - "CreatedAt": "${createdAt.toISOString()}", - "UserId": ${userId} + "eventSlug": "${eventSlug}", + "createdAt": "${createdAt.toISOString()}", + "username": "${username}", + "userImageUrl": "${userImageUrl}" }`; const jsonWithoutCreatedAt = `{ - "EventId": ${eventId}, - "Content": "${content}", - "UserId": ${userId} + "eventSlug": "${eventSlug}", + "content": "${content}", + "username": "${username}", + "userImageUrl": "${userImageUrl}" }`; - const jsonWithoutUserId = `{ - "EventId": ${eventId}, - "Content": "${content}", - "CreatedAt": "${createdAt.toISOString()}" + const jsonWithoutUsername = `{ + "eventSlug": "${eventSlug}", + "content": "${content}", + "createdAt": "${createdAt.toISOString()}", + "userImageUrl": "${userImageUrl}" }`; - expect(() => CommentDtoMapper.fromJSON(jsonWithoutEventId)).toThrow( + const jsonWithoutUserImageUrl = `{ + "eventSlug": "${eventSlug}", + "content": "${content}", + "createdAt": "${createdAt.toISOString()}", + "username": "${username}" + }`; + + expect(() => CommentDtoMapper.fromJSON(jsonWithoutEventSlug)).toThrow( ModelMappingError, ); expect(() => CommentDtoMapper.fromJSON(jsonWithoutContent)).toThrow( @@ -66,7 +80,10 @@ describe("CommentDto", () => { expect(() => CommentDtoMapper.fromJSON(jsonWithoutCreatedAt)).toThrow( ModelMappingError, ); - expect(() => CommentDtoMapper.fromJSON(jsonWithoutUserId)).toThrow( + expect(() => CommentDtoMapper.fromJSON(jsonWithoutUsername)).toThrow( + ModelMappingError, + ); + expect(() => CommentDtoMapper.fromJSON(jsonWithoutUserImageUrl)).toThrow( ModelMappingError, ); }); @@ -75,57 +92,71 @@ describe("CommentDto", () => { describe("fromObject", () => { it("should create an instance of CommentDto from an object", () => { const object = { - EventId: eventId, - Content: content, - CreatedAt: createdAt, - UserId: userId, + eventSlug: eventSlug, + content: content, + createdAt: createdAt, + username: username, + userImageUrl: userImageUrl, }; let comment = CommentDtoMapper.fromObject(object); comment = comment as CommentDto; - expect(comment.EventId).toBe(eventId); - expect(comment.Content).toBe(content); - expect(comment.CreatedAt).toEqual(createdAt); - expect(comment.UserId).toBe(userId); + expect(comment.eventSlug).toBe(eventSlug); + expect(comment.content).toBe(content); + expect(comment.createdAt).toEqual(createdAt); + expect(comment.username).toBe(username); + expect(comment.userImageUrl).toBe(userImageUrl); }); it("should throw an error if the object is invalid", () => { const object = { - EventId: eventId, - Content: true, - CreatedAt: createdAt, - UserId: null, + eventSlug: eventSlug, + content: true, + createdAt: createdAt, + username: null, + userImageUrl: userImageUrl, }; - const objectWithoutEventId = { - Content: content, - CreatedAt: createdAt, - UserId: userId, + const objectWithoutEventSlug = { + content: content, + createdAt: createdAt, + username: username, + userImageUrl: userImageUrl, }; const objectWithoutContent = { - EventId: eventId, - CreatedAt: createdAt, - UserId: userId, + eventSlug: eventSlug, + createdAt: createdAt, + username: username, + userImageUrl: userImageUrl, }; const objectWithoutCreatedAt = { - EventId: eventId, - Content: content, - UserId: userId, + eventSlug: eventSlug, + content: content, + username: username, + userImageUrl: userImageUrl, + }; + + const objectWithoutUsername = { + eventSlug: eventSlug, + content: content, + createdAt: createdAt, + userImageUrl: userImageUrl, }; - const objectWithoutUserId = { - EventId: eventId, - Content: content, - CreatedAt: createdAt, + const objectWithoutUserImageUrl = { + eventSlug: eventSlug, + content: content, + createdAt: createdAt, + username: username, }; expect(() => CommentDtoMapper.fromObject(object)).toThrow( ModelMappingError, ); - expect(() => CommentDtoMapper.fromObject(objectWithoutEventId)).toThrow( + expect(() => CommentDtoMapper.fromObject(objectWithoutEventSlug)).toThrow( ModelMappingError, ); expect(() => CommentDtoMapper.fromObject(objectWithoutContent)).toThrow( @@ -134,24 +165,29 @@ describe("CommentDto", () => { expect(() => CommentDtoMapper.fromObject(objectWithoutCreatedAt)).toThrow( ModelMappingError, ); - expect(() => CommentDtoMapper.fromObject(objectWithoutUserId)).toThrow( + expect(() => CommentDtoMapper.fromObject(objectWithoutUsername)).toThrow( ModelMappingError, ); + expect(() => + CommentDtoMapper.fromObject(objectWithoutUserImageUrl), + ).toThrow(ModelMappingError); }); it("should throw an error if date is in incorrect format", () => { const object = { - EventId: eventId, - Content: content, - CreatedAt: "invalid date", - UserId: userId, + eventSlug: eventSlug, + content: content, + createdAt: "invalid date", + username: username, + userImageUrl: userImageUrl, }; const objectMissingZ = { - EventId: eventId, - Content: content, - CreatedAt: "2009-06-15T13:45:30.0000000", - UserId: userId, + eventSlug: eventSlug, + content: content, + createdAt: "2009-06-15T13:45:30.0000000", + username: username, + userImageUrl: userImageUrl, }; expect(() => CommentDtoMapper.fromObject(object)).toThrow( @@ -164,44 +200,47 @@ describe("CommentDto", () => { it("should properly parse date string", () => { const object = { - EventId: eventId, - Content: content, - CreatedAt: "2009-06-15T13:45:30.0000000-07:00", - UserId: userId, + eventSlug: eventSlug, + content: content, + createdAt: "2009-06-15T13:45:30.0000000-07:00", + username: username, + userImageUrl: userImageUrl, }; const objectWithoutOffset = { - EventId: eventId, - Content: content, - CreatedAt: "2009-06-15T13:45:30.0000000Z", - UserId: userId, + eventSlug: eventSlug, + content: content, + createdAt: "2009-06-15T13:45:30.0000000Z", + username: username, + userImageUrl: userImageUrl, }; const objectWithoutMilliseconds = { - EventId: eventId, - Content: content, - CreatedAt: "2009-06-15T13:45:30Z", - UserId: userId, + eventSlug: eventSlug, + content: content, + createdAt: "2009-06-15T13:45:30Z", + username: username, + userImageUrl: userImageUrl, }; let comment = CommentDtoMapper.fromObject(object); comment = comment as CommentDto; - expect(comment.CreatedAt).toEqual( + expect(comment.createdAt).toEqual( new Date("2009-06-15T13:45:30.0000000-07:00"), ); comment = CommentDtoMapper.fromObject(objectWithoutOffset); comment = comment as CommentDto; - expect(comment.CreatedAt).toEqual( + expect(comment.createdAt).toEqual( new Date("2009-06-15T13:45:30.0000000Z"), ); comment = CommentDtoMapper.fromObject(objectWithoutMilliseconds); comment = comment as CommentDto; - expect(comment.CreatedAt).toEqual(new Date("2009-06-15T13:45:30Z")); + expect(comment.createdAt).toEqual(new Date("2009-06-15T13:45:30Z")); }); }); }); diff --git a/Client/reasn-client/packages/common/__tests__/schemas/EventDto.test.ts b/Client/reasn-client/packages/common/__tests__/schemas/EventDto.test.ts deleted file mode 100644 index 73a7a9dd..00000000 --- a/Client/reasn-client/packages/common/__tests__/schemas/EventDto.test.ts +++ /dev/null @@ -1,463 +0,0 @@ -import { EventDto, EventDtoMapper } from "@reasn/common/src/schemas/EventDto"; -import { EventStatus } from "@reasn/common/src/enums/schemasEnums"; -import ModelMappingError from "@reasn/common/src/errors/ModelMappingError"; -import { TagDto } from "@reasn/common/src/schemas/TagDto"; - -describe("EventDto", () => { - const name = "Test Event"; - const addressId = 1; - const description = "This is a test event"; - const organizerId = 1; - const startAt = new Date("2022-01-01"); - const endAt = new Date("2022-01-02"); - const createdAt = new Date("2022-01-01"); - const updatedAt = new Date("2022-01-01"); - const slug = "test-event"; - const status = EventStatus.APPROVED; - const tags: TagDto[] = [{ Name: "first tag" }, { Name: "second tag" }]; - - describe("fromJson", () => { - it("should create an instance of EventDto from JSON string", () => { - const json = `{ - "Name": "${name}", - "AddressId": ${addressId}, - "Description": "${description}", - "OrganizerId": ${organizerId}, - "StartAt": "${startAt.toISOString()}", - "EndAt": "${endAt.toISOString()}", - "CreatedAt": "${createdAt.toISOString()}", - "UpdatedAt": "${updatedAt.toISOString()}", - "Slug": "${slug}", - "Status": "${status}", - "Tags": ${JSON.stringify(tags)} - }`; - - let event = EventDtoMapper.fromJSON(json); - event = event as EventDto; - - expect(event.Name).toBe(name); - expect(event.AddressId).toBe(addressId); - expect(event.Description).toBe(description); - expect(event.OrganizerId).toBe(organizerId); - expect(event.StartAt).toEqual(startAt); - expect(event.EndAt).toEqual(endAt); - expect(event.CreatedAt).toEqual(createdAt); - expect(event.UpdatedAt).toEqual(updatedAt); - expect(event.Slug).toBe(slug); - expect(event.Status).toBe(status); - expect(event.Tags).toEqual(tags); - }); - - it("should return null if the JSON string is empty", () => { - expect(() => EventDtoMapper.fromJSON("")).toThrow(ModelMappingError); - }); - - it("should throw an error when providing json without each property individually", () => { - const jsonWithoutName = `{ - "AddressId": ${addressId}, - "Description": "${description}", - "OrganizerId": ${organizerId}, - "StartAt": "${startAt.toISOString()}", - "EndAt": "${endAt.toISOString()}", - "CreatedAt": "${createdAt.toISOString()}", - "UpdatedAt": "${updatedAt.toISOString()}", - "Slug": "${slug}", - "Status": "${status}", - "Tags": ${JSON.stringify(tags)} - }`; - - const jsonWithoutAddressId = `{ - "Name": "${name}", - "Description": "${description}", - "OrganizerId": ${organizerId}, - "StartAt": "${startAt.toISOString()}", - "EndAt": "${endAt.toISOString()}", - "CreatedAt": "${createdAt.toISOString()}", - "UpdatedAt": "${updatedAt.toISOString()}", - "Slug": "${slug}", - "Status": "${status}", - "Tags": ${JSON.stringify(tags)} - }`; - - const jsonWithoutDescription = `{ - "Name": "${name}", - "AddressId": ${addressId}, - "OrganizerId": ${organizerId}, - "StartAt": "${startAt.toISOString()}", - "EndAt": "${endAt.toISOString()}", - "CreatedAt": "${createdAt.toISOString()}", - "UpdatedAt": "${updatedAt.toISOString()}", - "Slug": "${slug}", - "Status": "${status}", - "Tags": ${JSON.stringify(tags)} - }`; - - const jsonWithoutOrganizerId = `{ - "Name": "${name}", - "AddressId": ${addressId}, - "Description": "${description}", - "StartAt": "${startAt.toISOString()}", - "EndAt": "${endAt.toISOString()}", - "CreatedAt": "${createdAt.toISOString()}", - "UpdatedAt": "${updatedAt.toISOString()}", - "Slug": "${slug}", - "Status": "${status}", - "Tags": ${JSON.stringify(tags)} - }`; - - const jsonWithoutStartAt = `{ - "Name": "${name}", - "AddressId": ${addressId}, - "Description": "${description}", - "OrganizerId": ${organizerId}, - "EndAt": "${endAt.toISOString()}", - "CreatedAt": "${createdAt.toISOString()}", - "UpdatedAt": "${updatedAt.toISOString()}", - "Slug": "${slug}", - "Status": "${status}", - "Tags": ${JSON.stringify(tags)} - }`; - - const jsonWithoutEndAt = `{ - "Name": "${name}", - "AddressId": ${addressId}, - "Description": "${description}", - "OrganizerId": ${organizerId}, - "StartAt": "${startAt.toISOString()}", - "CreatedAt": "${createdAt.toISOString()}", - "UpdatedAt": "${updatedAt.toISOString()}", - "Slug": "${slug}", - "Status": "${status}", - "Tags": ${JSON.stringify(tags)} - }`; - - const jsonWithoutCreatedAt = `{ - "Name": "${name}", - "AddressId": ${addressId}, - "Description": "${description}", - "OrganizerId": ${organizerId}, - "StartAt": "${startAt.toISOString()}", - "EndAt": "${endAt.toISOString()}", - "UpdatedAt": "${updatedAt.toISOString()}", - "Slug": "${slug}", - "Status": "${status}", - "Tags": ${JSON.stringify(tags)} - }`; - - const jsonWithoutUpdatedAt = `{ - "Name": "${name}", - "AddressId": ${addressId}, - "Description": "${description}", - "OrganizerId": ${organizerId}, - "StartAt": "${startAt.toISOString()}", - "EndAt": "${endAt.toISOString()}", - "CreatedAt": "${createdAt.toISOString()}", - "Slug": "${slug}", - "Status": "${status}", - "Tags": ${JSON.stringify(tags)} - }`; - - const jsonWithoutSlug = `{ - "Name": "${name}", - "AddressId": ${addressId}, - "Description": "${description}", - "OrganizerId": ${organizerId}, - "StartAt": "${startAt.toISOString()}", - "EndAt": "${endAt.toISOString()}", - "CreatedAt": "${createdAt.toISOString()}", - "UpdatedAt": "${updatedAt.toISOString()}", - "Status": "${status}", - "Tags": ${JSON.stringify(tags)} - }`; - - const jsonWithoutStatus = `{ - "Name": "${name}", - "AddressId": ${addressId}, - "Description": "${description}", - "OrganizerId": ${organizerId}, - "StartAt": "${startAt.toISOString()}", - "EndAt": "${endAt.toISOString()}", - "CreatedAt": "${createdAt.toISOString()}", - "UpdatedAt": "${updatedAt.toISOString()}", - "Slug": "${slug}", - "Tags": ${JSON.stringify(tags)} - }`; - - const jsonWithoutTags = `{ - "Name": "${name}", - "AddressId": ${addressId}, - "Description": "${description}", - "OrganizerId": ${organizerId}, - "StartAt": "${startAt.toISOString()}", - "EndAt": "${endAt.toISOString()}", - "CreatedAt": "${createdAt.toISOString()}", - "UpdatedAt": "${updatedAt.toISOString()}", - "Slug": "${slug}", - "Status": "${status}" - }`; - - expect(() => { - EventDtoMapper.fromJSON(jsonWithoutName); - }).toThrow(ModelMappingError); - expect(() => { - EventDtoMapper.fromJSON(jsonWithoutAddressId); - }).toThrow(ModelMappingError); - expect(() => { - EventDtoMapper.fromJSON(jsonWithoutDescription); - }).toThrow(ModelMappingError); - expect(() => { - EventDtoMapper.fromJSON(jsonWithoutOrganizerId); - }).toThrow(ModelMappingError); - expect(() => { - EventDtoMapper.fromJSON(jsonWithoutStartAt); - }).toThrow(ModelMappingError); - expect(() => { - EventDtoMapper.fromJSON(jsonWithoutEndAt); - }).toThrow(ModelMappingError); - expect(() => { - EventDtoMapper.fromJSON(jsonWithoutCreatedAt); - }).toThrow(ModelMappingError); - expect(() => { - EventDtoMapper.fromJSON(jsonWithoutUpdatedAt); - }).toThrow(ModelMappingError); - expect(() => { - EventDtoMapper.fromJSON(jsonWithoutSlug); - }).toThrow(ModelMappingError); - expect(() => { - EventDtoMapper.fromJSON(jsonWithoutStatus); - }).toThrow(ModelMappingError); - expect(() => { - EventDtoMapper.fromJSON(jsonWithoutTags); - }).toThrow(ModelMappingError); - }); - }); - - describe("fromObject", () => { - it("should create an instance of EventDto from an object", () => { - const obj = { - Name: name, - AddressId: addressId, - Description: description, - OrganizerId: organizerId, - StartAt: startAt, - EndAt: endAt, - CreatedAt: createdAt, - UpdatedAt: updatedAt, - Slug: slug, - Status: status, - Tags: tags, - }; - - let event = EventDtoMapper.fromObject(obj); - event = event as EventDto; - - expect(event.Name).toBe(name); - expect(event.AddressId).toBe(addressId); - expect(event.Description).toBe(description); - expect(event.OrganizerId).toBe(organizerId); - expect(event.StartAt).toEqual(startAt); - expect(event.EndAt).toEqual(endAt); - expect(event.CreatedAt).toEqual(createdAt); - expect(event.UpdatedAt).toEqual(updatedAt); - expect(event.Slug).toBe(slug); - expect(event.Status).toBe(status); - expect(event.Tags).toEqual(tags); - }); - - it("should return null if the object is invalid", () => { - const invalidObj = { - Name: 1, - AddressId: null, - Description: 65, - OrganizerId: true, - StartAt: "abc", - EndAt: NaN, - CreatedAt: -1, - UpdatedAt: "true", - Slug: undefined, - StatusId: -45, - Tags: "no tags", - }; - - const objWithoutName = { - AddressId: addressId, - Description: description, - OrganizerId: organizerId, - StartAt: startAt, - EndAt: endAt, - CreatedAt: createdAt, - UpdatedAt: updatedAt, - Slug: slug, - Status: status, - Tags: tags, - }; - - const objWithoutAddressId = { - Name: name, - Description: description, - OrganizerId: organizerId, - StartAt: startAt, - EndAt: endAt, - CreatedAt: createdAt, - UpdatedAt: updatedAt, - Slug: slug, - Status: status, - Tags: tags, - }; - - const objWithoutDescription = { - Name: name, - AddressId: addressId, - OrganizerId: organizerId, - StartAt: startAt, - EndAt: endAt, - CreatedAt: createdAt, - UpdatedAt: updatedAt, - Slug: slug, - Status: status, - Tags: tags, - }; - - const objWithoutOrganizerId = { - Name: name, - AddressId: addressId, - Description: description, - StartAt: startAt, - EndAt: endAt, - CreatedAt: createdAt, - UpdatedAt: updatedAt, - Slug: slug, - Status: status, - Tags: tags, - }; - - const objWithoutStartAt = { - Name: name, - AddressId: addressId, - Description: description, - OrganizerId: organizerId, - EndAt: endAt, - CreatedAt: createdAt, - UpdatedAt: updatedAt, - Slug: slug, - Status: status, - Tags: tags, - }; - - const objWithoutEndAt = { - Name: name, - AddressId: addressId, - Description: description, - OrganizerId: organizerId, - StartAt: startAt, - CreatedAt: createdAt, - UpdatedAt: updatedAt, - Slug: slug, - Status: status, - Tags: tags, - }; - - const objWithoutCreatedAt = { - Name: name, - AddressId: addressId, - Description: description, - OrganizerId: organizerId, - StartAt: startAt, - EndAt: endAt, - UpdatedAt: updatedAt, - Slug: slug, - Status: status, - Tags: tags, - }; - - const objWithoutUpdatedAt = { - Name: name, - AddressId: addressId, - Description: description, - OrganizerId: organizerId, - StartAt: startAt, - EndAt: endAt, - CreatedAt: createdAt, - Slug: slug, - Status: status, - Tags: tags, - }; - - const objWithoutSlug = { - Name: name, - AddressId: addressId, - Description: description, - OrganizerId: organizerId, - StartAt: startAt, - EndAt: endAt, - CreatedAt: createdAt, - UpdatedAt: updatedAt, - Status: status, - Tags: tags, - }; - - const objWithoutStatusId = { - Name: name, - AddressId: addressId, - Description: description, - OrganizerId: organizerId, - StartAt: startAt, - EndAt: endAt, - CreatedAt: createdAt, - UpdatedAt: updatedAt, - Slug: slug, - Tags: tags, - }; - - const objWithoutTags = { - Name: name, - AddressId: addressId, - Description: description, - OrganizerId: organizerId, - StartAt: startAt, - EndAt: endAt, - CreatedAt: createdAt, - UpdatedAt: updatedAt, - Slug: slug, - Status: status, - }; - - expect(() => { - EventDtoMapper.fromObject(invalidObj); - }).toThrow(ModelMappingError); - expect(() => { - EventDtoMapper.fromObject(objWithoutName); - }).toThrow(ModelMappingError); - expect(() => { - EventDtoMapper.fromObject(objWithoutAddressId); - }).toThrow(ModelMappingError); - expect(() => { - EventDtoMapper.fromObject(objWithoutDescription); - }).toThrow(ModelMappingError); - expect(() => { - EventDtoMapper.fromObject(objWithoutOrganizerId); - }).toThrow(ModelMappingError); - expect(() => { - EventDtoMapper.fromObject(objWithoutStartAt); - }).toThrow(ModelMappingError); - expect(() => { - EventDtoMapper.fromObject(objWithoutEndAt); - }).toThrow(ModelMappingError); - expect(() => { - EventDtoMapper.fromObject(objWithoutCreatedAt); - }).toThrow(ModelMappingError); - expect(() => { - EventDtoMapper.fromObject(objWithoutUpdatedAt); - }).toThrow(ModelMappingError); - expect(() => { - EventDtoMapper.fromObject(objWithoutSlug); - }).toThrow(ModelMappingError); - expect(() => { - EventDtoMapper.fromObject(objWithoutStatusId); - }).toThrow(ModelMappingError); - expect(() => { - EventDtoMapper.fromObject(objWithoutTags); - }).toThrow(ModelMappingError); - }); - }); -}); diff --git a/Client/reasn-client/packages/common/__tests__/schemas/ImageDto.test.ts b/Client/reasn-client/packages/common/__tests__/schemas/ImageDto.test.ts deleted file mode 100644 index 8d8df35f..00000000 --- a/Client/reasn-client/packages/common/__tests__/schemas/ImageDto.test.ts +++ /dev/null @@ -1,110 +0,0 @@ -import { ImageDto, ImageDtoMapper } from "@reasn/common/src/schemas/ImageDto"; -import { ObjectType } from "@reasn/common/src/enums/schemasEnums"; -import ModelMappingError from "@reasn/common/src/errors/ModelMappingError"; - -describe("ImageDto", () => { - const imageData = "Test Image"; - const objectId = 1; - const objectType = ObjectType.USER; - - describe("fromJson", () => { - it("should create an instance of ImageDto from JSON string", () => { - const json = `{ - "ImageData": "${imageData}", - "ObjectId": ${objectId}, - "ObjectType": "${objectType}" - }`; - - let image = ImageDtoMapper.fromJSON(json); - image = image as ImageDto; - - expect(image.ImageData).toBe(imageData); - expect(image.ObjectId).toBe(objectId); - expect(image.ObjectType).toBe(objectType); - }); - - it("should return null if the JSON string is empty", () => { - expect(() => ImageDtoMapper.fromJSON("")).toThrow(ModelMappingError); - }); - - it("should throw an error when providing json without each property individually", () => { - const jsonWithoutImageData = `{ - "ObjectId": ${objectId}, - "ObjectType": "${objectType}" - }`; - - const jsonWithoutObjectId = `{ - "ImageData": "${imageData}", - "ObjectType": "${objectType}" - }`; - - const jsonWithoutObjectTypeId = `{ - "ImageData": "${imageData}", - "ObjectId": ${objectId} - }`; - - expect(() => ImageDtoMapper.fromJSON(jsonWithoutImageData)).toThrow( - ModelMappingError, - ); - expect(() => ImageDtoMapper.fromJSON(jsonWithoutObjectId)).toThrow( - ModelMappingError, - ); - expect(() => ImageDtoMapper.fromJSON(jsonWithoutObjectTypeId)).toThrow( - ModelMappingError, - ); - }); - }); - - describe("fromObject", () => { - it("should create an instance of ImageDto from an object", () => { - const object = { - ImageData: imageData, - ObjectId: objectId, - ObjectType: objectType, - }; - - let image = ImageDtoMapper.fromObject(object); - image = image as ImageDto; - - expect(image.ImageData).toBe(imageData); - expect(image.ObjectId).toBe(objectId); - expect(image.ObjectType).toBe(objectType); - }); - - it("should throw an error if the object is invalid", () => { - const object = { - ImageData: true, - ObjectId: null, - ObjectType: undefined, - }; - - const objectWithoutImageData = { - ObjectId: objectId, - ObjectType: objectType, - }; - - const objectWithoutObjectId = { - ImageData: imageData, - ObjectType: objectType, - }; - - const objectWithoutObjectType = { - ImageData: imageData, - ObjectId: objectId, - }; - - expect(() => ImageDtoMapper.fromObject(object)).toThrow( - ModelMappingError, - ); - expect(() => ImageDtoMapper.fromObject(objectWithoutImageData)).toThrow( - ModelMappingError, - ); - expect(() => ImageDtoMapper.fromObject(objectWithoutObjectId)).toThrow( - ModelMappingError, - ); - expect(() => ImageDtoMapper.fromObject(objectWithoutObjectType)).toThrow( - ModelMappingError, - ); - }); - }); -}); diff --git a/Client/reasn-client/packages/common/__tests__/schemas/InterestDto.test.ts b/Client/reasn-client/packages/common/__tests__/schemas/InterestDto.test.ts index af828f5f..ea1fd21d 100644 --- a/Client/reasn-client/packages/common/__tests__/schemas/InterestDto.test.ts +++ b/Client/reasn-client/packages/common/__tests__/schemas/InterestDto.test.ts @@ -10,13 +10,13 @@ describe("InterestDto", () => { describe("fromJson", () => { it("should create an instance of InterestDto from JSON string", () => { const json = `{ - "Name": "${name}" + "name": "${name}" }`; let interest = InterestDtoMapper.fromJSON(json); interest = interest as InterestDto; - expect(interest.Name).toBe(name); + expect(interest.name).toBe(name); }); it("should return null if the JSON string is empty", () => { @@ -35,13 +35,13 @@ describe("InterestDto", () => { describe("fromObject", () => { it("should create an instance of InterestDto from an object", () => { const object = { - Name: name, + name: name, }; let interest = InterestDtoMapper.fromObject(object); interest = interest as InterestDto; - expect(interest.Name).toBe(name); + expect(interest.name).toBe(name); }); it("should throw an error if the object is invalid", () => { diff --git a/Client/reasn-client/packages/common/__tests__/schemas/ParameterDto.test.ts b/Client/reasn-client/packages/common/__tests__/schemas/ParameterDto.test.ts index 68ee9c81..e3fbf8ef 100644 --- a/Client/reasn-client/packages/common/__tests__/schemas/ParameterDto.test.ts +++ b/Client/reasn-client/packages/common/__tests__/schemas/ParameterDto.test.ts @@ -11,15 +11,15 @@ describe("ParameterDto", () => { describe("fromJson", () => { it("should create an instance of ParameterDto from JSON string", () => { const json = `{ - "Key": "${key}", - "Value": "${value}" + "key": "${key}", + "value": "${value}" }`; let parameter = ParameterDtoMapper.fromJSON(json); parameter = parameter as ParameterDto; - expect(parameter.Key).toBe(key); - expect(parameter.Value).toBe(value); + expect(parameter.key).toBe(key); + expect(parameter.value).toBe(value); }); it("should return null if the JSON string is empty", () => { @@ -28,11 +28,11 @@ describe("ParameterDto", () => { it("should throw an error when providing json without each property individually", () => { const jsonWithoutKey = `{ - "Value": "${value}" + "value": "${value}" }`; const jsonWithoutValue = `{ - "Key": "${key}" + "key": "${key}" }`; expect(() => ParameterDtoMapper.fromJSON(jsonWithoutKey)).toThrow( @@ -47,29 +47,29 @@ describe("ParameterDto", () => { describe("fromObject", () => { it("should create an instance of ParameterDto from an object", () => { const object = { - Key: key, - Value: value, + key: key, + value: value, }; let parameter = ParameterDtoMapper.fromObject(object); parameter = parameter as ParameterDto; - expect(parameter.Key).toBe(key); - expect(parameter.Value).toBe(value); + expect(parameter.key).toBe(key); + expect(parameter.value).toBe(value); }); it("should throw an error if the object is invalid", () => { const object = { - Key: true, - Value: null, + key: true, + value: null, }; const objectWithoutKey = { - Value: value, + value: value, }; const objectWithoutValue = { - Key: key, + key: key, }; expect(() => ParameterDtoMapper.fromObject(object)).toThrow( 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 8218b83a..bea32185 100644 --- a/Client/reasn-client/packages/common/__tests__/schemas/ParticipantDto.test.ts +++ b/Client/reasn-client/packages/common/__tests__/schemas/ParticipantDto.test.ts @@ -13,17 +13,17 @@ describe("ParticipantDto", () => { describe("fromJson", () => { it("should create an instance of ParticipantDto from JSON string", () => { const json = `{ - "EventSlug": "${eventSlug}", - "Username": "${username}", - "Status": "${status}" + "eventSlug": "${eventSlug}", + "username": "${username}", + "status": "${status}" }`; let participant = ParticipantDtoMapper.fromJSON(json); participant = participant as ParticipantDto; - expect(participant.EventSlug).toBe(eventSlug); - expect(participant.Username).toBe(username); - expect(participant.Status).toBe(status); + expect(participant.eventSlug).toBe(eventSlug); + expect(participant.username).toBe(username); + expect(participant.status).toBe(status); }); it("should return null if the JSON string is empty", () => { @@ -34,18 +34,18 @@ describe("ParticipantDto", () => { it("should throw an error when providing JSON without each property individually", () => { const jsonWithoutEventSlug = `{ - "Username": "${username}", - "Status": "${status}" + "username": "${username}", + "status": "${status}" }`; const jsonWithoutUsername = `{ - "EventSlug": "${eventSlug}", - "Status": "${status}" + "eventSlug": "${eventSlug}", + "status": "${status}" }`; const jsonWithoutStatus = `{ - "EventSlug": "${eventSlug}", - "Username": "${username}" + "eventSlug": "${eventSlug}", + "username": "${username}" }`; expect(() => ParticipantDtoMapper.fromJSON(jsonWithoutEventSlug)).toThrow( @@ -63,39 +63,39 @@ describe("ParticipantDto", () => { describe("fromObject", () => { it("should create an instance of ParticipantDto from an object", () => { const object = { - EventSlug: eventSlug, - Username: username, - Status: status, + eventSlug: eventSlug, + username: username, + status: status, }; let participant = ParticipantDtoMapper.fromObject(object); participant = participant as ParticipantDto; - expect(participant.EventSlug).toBe(eventSlug); - expect(participant.Username).toBe(username); - expect(participant.Status).toBe(status); + 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 = { - EventStatus: true, - Username: null, - Status: "invalid", + eventStatus: true, + username: null, + status: "invalid", }; const objectWithoutEventSlug = { - Username: username, - Status: status, + username: username, + status: status, }; const objectWithoutUsername = { - EventSlug: eventSlug, - Status: status, + eventSlug: eventSlug, + status: status, }; const objectWithoutStatus = { - EventSlug: eventSlug, - Username: username, + eventSlug: eventSlug, + username: username, }; expect(() => ParticipantDtoMapper.fromObject(object)).toThrow( diff --git a/Client/reasn-client/packages/common/__tests__/schemas/TagDto.test.ts b/Client/reasn-client/packages/common/__tests__/schemas/TagDto.test.ts index aefba118..5f323d8d 100644 --- a/Client/reasn-client/packages/common/__tests__/schemas/TagDto.test.ts +++ b/Client/reasn-client/packages/common/__tests__/schemas/TagDto.test.ts @@ -7,13 +7,13 @@ describe("TagDto", () => { describe("fromJson", () => { it("should create an instance of TagDto from JSON string", () => { const json = `{ - "Name": "${name}" + "name": "${name}" }`; let tag = TagDtoMapper.fromJSON(json); tag = tag as TagDto; - expect(tag.Name).toBe(name); + expect(tag.name).toBe(name); }); it("should return null if the JSON string is empty", () => { @@ -32,18 +32,18 @@ describe("TagDto", () => { describe("fromObject", () => { it("should create an instance of TagDto from an object", () => { const object = { - Name: name, + name: name, }; let tag = TagDtoMapper.fromObject(object); tag = tag as TagDto; - expect(tag.Name).toBe(name); + expect(tag.name).toBe(name); }); it("should throw an error if the object is invalid", () => { const object = { - Name: null, + name: null, }; const objectWithoutName = {}; 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 fcefd5ad..83f28299 100644 --- a/Client/reasn-client/packages/common/__tests__/schemas/UserDto.test.ts +++ b/Client/reasn-client/packages/common/__tests__/schemas/UserDto.test.ts @@ -20,8 +20,8 @@ describe("UserDto", () => { zipCode: "12345", }; const interests: UserInterestDto[] = [ - { Interest: { Name: "Programming" }, Level: 5 }, - { Interest: { Name: "Music" }, Level: 3 }, + { interest: { name: "Programming" }, level: 5 }, + { interest: { name: "Music" }, level: 3 }, ]; describe("fromJson", () => { diff --git a/Client/reasn-client/packages/common/__tests__/schemas/UserInterestDto.test.ts b/Client/reasn-client/packages/common/__tests__/schemas/UserInterestDto.test.ts index e8c1283c..f58c4e6b 100644 --- a/Client/reasn-client/packages/common/__tests__/schemas/UserInterestDto.test.ts +++ b/Client/reasn-client/packages/common/__tests__/schemas/UserInterestDto.test.ts @@ -6,21 +6,21 @@ import { import ModelMappingError from "@reasn/common/src/errors/ModelMappingError"; describe("UserInterestDto", () => { - const interest = { Name: "Interest" } as InterestDto; + const interest = { name: "Interest" } as InterestDto; const level = 1; describe("fromJson", () => { it("should create an instance of UserInterestDto from JSON string", () => { const json = `{ - "Interest": { "Name": "${interest.Name}" }, - "Level": ${level} + "interest": { "name": "${interest.name}" }, + "level": ${level} }`; let userInterest = UserInterestDtoMapper.fromJSON(json); userInterest = userInterest as UserInterestDto; - expect(userInterest.Interest.Name).toBe(interest.Name); - expect(userInterest.Level).toBe(level); + expect(userInterest.interest.name).toBe(interest.name); + expect(userInterest.level).toBe(level); }); it("should return null if the JSON string is empty", () => { @@ -31,11 +31,11 @@ describe("UserInterestDto", () => { it("should throw an error when providing json without each property individaully", () => { const jsonWithoutInterest = `{ - "Level": ${level} + "level": ${level} }`; const jsonWithoutLevel = `{ - "Interest": { "Name": "${interest.Name}" } + "interest": { "Name": "${interest.name}" } }`; expect(() => UserInterestDtoMapper.fromJSON(jsonWithoutInterest)).toThrow( @@ -50,29 +50,29 @@ describe("UserInterestDto", () => { describe("fromObject", () => { it("should create an instance of UserInterestDto from an object", () => { const object = { - Interest: interest, - Level: level, + interest: interest, + level: level, }; let userInterest = UserInterestDtoMapper.fromObject(object); userInterest = userInterest as UserInterestDto; - expect(userInterest.Interest.Name).toBe(interest.Name); - expect(userInterest.Level).toBe(level); + expect(userInterest.interest.name).toBe(interest.name); + expect(userInterest.level).toBe(level); }); it("should throw an error if the object is invalid", () => { const object = { - Interest: { Name: 1 }, - Level: true, + interest: { name: 1 }, + level: true, }; const objectWithoutInterest = { - Level: level, + level: level, }; const objectWithoutLevel = { - Interest: interest, + interest: interest, }; expect(() => UserInterestDtoMapper.fromObject(object)).toThrow( diff --git a/Client/reasn-client/packages/common/src/schemas/CommentDto.ts b/Client/reasn-client/packages/common/src/schemas/CommentDto.ts index abe54755..13f9aa75 100644 --- a/Client/reasn-client/packages/common/src/schemas/CommentDto.ts +++ b/Client/reasn-client/packages/common/src/schemas/CommentDto.ts @@ -2,14 +2,21 @@ import ModelMappingError from "../errors/ModelMappingError"; import { z } from "zod"; export const CommentDtoSchema = z.object({ - EventId: z.number(), - Content: z.string().max(1024), - CreatedAt: z + eventSlug: z + .string() + .max(128) + .regex(/^[\p{L}\d]+[\p{L}\d-]*$/u), + content: z.string().max(1024), + createdAt: z .string() .datetime({ offset: true }) .or(z.date()) .transform((arg) => new Date(arg)), - UserId: z.number(), + username: z + .string() + .max(64) + .regex(/^[\p{L}\d._%+-]{4,}$/u), + userImageUrl: z.string().nullable(), }); export type CommentDto = z.infer; diff --git a/Client/reasn-client/packages/common/src/schemas/CommentRequest.ts b/Client/reasn-client/packages/common/src/schemas/CommentRequest.ts new file mode 100644 index 00000000..53c95e53 --- /dev/null +++ b/Client/reasn-client/packages/common/src/schemas/CommentRequest.ts @@ -0,0 +1,7 @@ +import { z } from "zod"; + +export const CommentRequestSchema = z.object({ + content: z.string().max(1024), +}); + +export type CommentRequest = z.infer; diff --git a/Client/reasn-client/packages/common/src/schemas/EventDto.ts b/Client/reasn-client/packages/common/src/schemas/EventDto.ts deleted file mode 100644 index a9c1e0ba..00000000 --- a/Client/reasn-client/packages/common/src/schemas/EventDto.ts +++ /dev/null @@ -1,73 +0,0 @@ -import ModelMappingError from "../errors/ModelMappingError"; -import { TagDtoSchema } from "./TagDto"; -import { EventStatus } from "../enums/schemasEnums"; -import { z } from "zod"; - -export const EventDtoSchema = z.object({ - Name: z.string().max(64), - AddressId: z.number(), - Description: z.string().max(4048), - OrganizerId: z.number(), - StartAt: z - .string() - .datetime({ offset: true }) - .or(z.date()) - .transform((arg) => new Date(arg)), - EndAt: z - .string() - .datetime({ offset: true }) - .or(z.date()) - .transform((arg) => new Date(arg)), - CreatedAt: z - .string() - .datetime({ offset: true }) - .or(z.date()) - .transform((arg) => new Date(arg)), - UpdatedAt: z - .string() - .datetime({ offset: true }) - .or(z.date()) - .transform((arg) => new Date(arg)), - Slug: z - .string() - .nullable() - .refine( - (value) => - value === null || - (value.length <= 128 && /^[\p{L}\d]+[\p{L}\d-]*$/u.test(value)), - ), - - Status: z.nativeEnum(EventStatus), - - Tags: z.array(TagDtoSchema), -}); - -export type EventDto = z.infer; - -export const EventDtoMapper = { - fromObject: (entity: object): EventDto => { - const result = EventDtoSchema.safeParse(entity); - if (!result.success) { - throw new ModelMappingError( - "EventDto", - result.error.message, - result.error, - ); - } - return result.data; - }, - fromJSON: (jsonEntity: string): any => { - if (!jsonEntity) { - throw new ModelMappingError("EventDto", "Empty JSON string"); - } - const result = EventDtoSchema.safeParse(JSON.parse(jsonEntity)); - if (!result.success) { - throw new ModelMappingError( - "EventDto", - result.error.message, - result.error, - ); - } - return result.data; - }, -}; diff --git a/Client/reasn-client/packages/common/src/schemas/EventResponse.ts b/Client/reasn-client/packages/common/src/schemas/EventResponse.ts index 3eecda7e..e3a4e5a7 100644 --- a/Client/reasn-client/packages/common/src/schemas/EventResponse.ts +++ b/Client/reasn-client/packages/common/src/schemas/EventResponse.ts @@ -40,12 +40,15 @@ export const EventRespsoneSchema = z.object({ .regex(/^[\p{L}\d]+[\p{L}\d-]*$/u) .nullable(), status: z.nativeEnum(EventStatus), - tags: z.array(TagDtoSchema), - parameters: z.array(ParameterDtoSchema), - participants: z.object({ - interested: z.number(), - participating: z.number(), - }), + tags: z.array(TagDtoSchema).nullable(), + parameters: z.array(ParameterDtoSchema).nullable(), + participants: z + .object({ + interested: z.number(), + participating: z.number(), + }) + .nullable(), + images: z.array(z.string()).nullable(), }); export type EventResponse = z.infer; diff --git a/Client/reasn-client/packages/common/src/schemas/ImageDto.ts b/Client/reasn-client/packages/common/src/schemas/ImageDto.ts deleted file mode 100644 index 5af26865..00000000 --- a/Client/reasn-client/packages/common/src/schemas/ImageDto.ts +++ /dev/null @@ -1,39 +0,0 @@ -import ModelMappingError from "../errors/ModelMappingError"; -import { ObjectType } from "../enums/schemasEnums"; -import { z } from "zod"; - -export const ImageDtoSchema = z.object({ - ImageData: z.string(), - ObjectId: z.number(), - ObjectType: z.nativeEnum(ObjectType), -}); - -export type ImageDto = z.infer; - -export const ImageDtoMapper = { - fromObject: (entity: object): ImageDto => { - const result = ImageDtoSchema.safeParse(entity); - if (!result.success) { - throw new ModelMappingError( - "ImageDto", - result.error.message, - result.error, - ); - } - return result.data; - }, - fromJSON: (jsonEntity: string): any => { - if (!jsonEntity) { - throw new ModelMappingError("ImageDto", "Empty JSON string"); - } - const result = ImageDtoSchema.safeParse(JSON.parse(jsonEntity)); - if (!result.success) { - throw new ModelMappingError( - "ImageDto", - result.error.message, - result.error, - ); - } - return result.data; - }, -}; diff --git a/Client/reasn-client/packages/common/src/schemas/InterestDto.ts b/Client/reasn-client/packages/common/src/schemas/InterestDto.ts index 303e60c5..14bc0c03 100644 --- a/Client/reasn-client/packages/common/src/schemas/InterestDto.ts +++ b/Client/reasn-client/packages/common/src/schemas/InterestDto.ts @@ -2,7 +2,7 @@ import ModelMappingError from "../errors/ModelMappingError"; import { z } from "zod"; export const InterestDtoSchema = z.object({ - Name: z + name: z .string() .max(32) .regex(/^\p{Lu}\p{Ll}+(?:\s\p{L}+)*$/u), diff --git a/Client/reasn-client/packages/common/src/schemas/ParameterDto.ts b/Client/reasn-client/packages/common/src/schemas/ParameterDto.ts index 8006e2be..64daebec 100644 --- a/Client/reasn-client/packages/common/src/schemas/ParameterDto.ts +++ b/Client/reasn-client/packages/common/src/schemas/ParameterDto.ts @@ -2,11 +2,11 @@ import ModelMappingError from "../errors/ModelMappingError"; import { z } from "zod"; export const ParameterDtoSchema = z.object({ - Key: z + key: z .string() .max(32) .regex(/^\p{L}+(?:\s\p{L}+)*$/u), - Value: z + value: z .string() .max(64) .regex(/^[\p{L}\d]+(?:\s[\p{L}\d]+)*$/u), diff --git a/Client/reasn-client/packages/common/src/schemas/ParticipantDto.ts b/Client/reasn-client/packages/common/src/schemas/ParticipantDto.ts index 2f687e8b..d46baf87 100644 --- a/Client/reasn-client/packages/common/src/schemas/ParticipantDto.ts +++ b/Client/reasn-client/packages/common/src/schemas/ParticipantDto.ts @@ -3,9 +3,9 @@ import { ParticipantStatus } from "../enums/schemasEnums"; import { z } from "zod"; export const ParticipantDtoSchema = z.object({ - EventSlug: z.string(), - Username: z.string(), - Status: z.nativeEnum(ParticipantStatus), + eventSlug: z.string(), + username: z.string(), + status: z.nativeEnum(ParticipantStatus), }); export type ParticipantDto = z.infer; diff --git a/Client/reasn-client/packages/common/src/schemas/TagDto.ts b/Client/reasn-client/packages/common/src/schemas/TagDto.ts index b48334ea..6803b4f7 100644 --- a/Client/reasn-client/packages/common/src/schemas/TagDto.ts +++ b/Client/reasn-client/packages/common/src/schemas/TagDto.ts @@ -2,7 +2,7 @@ import ModelMappingError from "../errors/ModelMappingError"; import { z } from "zod"; export const TagDtoSchema = z.object({ - Name: z + name: z .string() .max(64) .regex(/^\p{L}+(?:\s\p{L}+)*$/u), diff --git a/Client/reasn-client/packages/common/src/schemas/UserInterestDto.ts b/Client/reasn-client/packages/common/src/schemas/UserInterestDto.ts index c561e470..ab3fb69e 100644 --- a/Client/reasn-client/packages/common/src/schemas/UserInterestDto.ts +++ b/Client/reasn-client/packages/common/src/schemas/UserInterestDto.ts @@ -3,8 +3,8 @@ import { InterestDtoSchema } from "../schemas/InterestDto"; import { z } from "zod"; export const UserInterestDtoSchema = z.object({ - Interest: InterestDtoSchema, - Level: z.number(), + interest: InterestDtoSchema, + level: z.number(), }); export type UserInterestDto = z.infer;