holy fuck.
This commit is contained in:
15
front/src/dto/AttendanceDto.ts
Normal file
15
front/src/dto/AttendanceDto.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import type {AttendeeDto} from "@/dto/AttendeeDto.ts";
|
||||
import type {TimeStampDto} from "@/dto/TimeStampDto.ts";
|
||||
|
||||
export class AttendanceDto {
|
||||
|
||||
public date : TimeStampDto
|
||||
public attendee : AttendeeDto
|
||||
|
||||
public constructor(date : TimeStampDto, attendee : AttendeeDto) {
|
||||
this.date = date;
|
||||
this.attendee = attendee;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,17 +1,18 @@
|
||||
import type {Attendee} from "@/models/Attendee.ts";
|
||||
import type {EventDate} from "@/models/EventDate.ts";
|
||||
import type {AttendeeDto} from "@/dto/AttendeeDto.ts";
|
||||
import { AttendanceDto } from "./AttendanceDto.ts";
|
||||
|
||||
export class EventDto {
|
||||
|
||||
public name: string;
|
||||
public token: string;
|
||||
public dates : Map<number, AttendeeDto[]>
|
||||
public attendances : AttendanceDto[];
|
||||
|
||||
public constructor(name: string, token: string, dates: Map<number, AttendeeDto[]>) {
|
||||
public constructor(name: string, token: string, attendances : AttendanceDto[]) {
|
||||
this.name = name;
|
||||
this.token = token;
|
||||
this.dates = dates;
|
||||
this.attendances = attendances;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
12
front/src/models/Attendance.ts
Normal file
12
front/src/models/Attendance.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import type {EventDate} from "@/models/EventDate.ts";
|
||||
import type {Attendee} from "@/models/Attendee.ts";
|
||||
|
||||
export class Attendance {
|
||||
public date : EventDate
|
||||
public attendee : Attendee
|
||||
|
||||
public constructor(date : EventDate, attendee : Attendee) {
|
||||
this.date = date;
|
||||
this.attendee = attendee;
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,8 @@ export class EventRequests {
|
||||
return fetch(url)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
return new EventDto(data.name, data.token, data.dates)
|
||||
console.log(data);
|
||||
return new EventDto(data.name, data.token, data.attendances);
|
||||
})
|
||||
.catch(error => console.error(error));
|
||||
}
|
||||
|
||||
@@ -3,14 +3,17 @@ import {EventRequests} from "@/requests/EventRequests.ts";
|
||||
import {EventDto} from "@/dto/EventDto.ts";
|
||||
import {Event, type EventState} from "@/models/Event.ts";
|
||||
import {Attendee, type AttendeeState} from "@/models/Attendee.ts";
|
||||
import type {AttendeeDto} from "@/dto/AttendeeDto.ts";
|
||||
import {AttendanceDto} from "@/dto/AttendanceDto.ts";
|
||||
import {TimeStampDto} from "@/dto/TimeStampDto.ts";
|
||||
import {AttendeeDto} from "@/dto/AttendeeDto.ts";
|
||||
|
||||
const requests = new EventRequests();
|
||||
|
||||
function mapToDto(state : EventState) : EventDto{
|
||||
let dates : Map<number, AttendeeDto[]> = new Map<number, AttendeeDto[]>();
|
||||
let dates : AttendanceDto[] = [];
|
||||
for (let [date, attendeesState] of state.dates.entries()) {
|
||||
dates.set(date, []);
|
||||
let attendance : AttendanceDto = new AttendanceDto(new TimeStampDto(new Date(date)), new AttendeeDto(""));
|
||||
dates.push(attendance);
|
||||
}
|
||||
return new EventDto(state.name, state.token, dates);
|
||||
}
|
||||
@@ -27,12 +30,15 @@ function mapToModel(state : EventState) : Event{
|
||||
}
|
||||
|
||||
function mapToState(dto : EventDto) : EventState {
|
||||
let event : EventState = {name : "", token : "", dates: new Map<number, AttendeeState[]>()};
|
||||
let event : EventState = { name : "", token : "", dates: new Map<number, AttendeeState[]>() };
|
||||
event.name = dto.name;
|
||||
event.token = dto.token;
|
||||
Object.entries(dto.dates).forEach(([key, attendees]) => {
|
||||
dto.attendances.forEach(value => {
|
||||
|
||||
})
|
||||
/*Object.entries(dto.dates).forEach(([key, attendees]) => {
|
||||
event.dates.set(Number(key), attendees);
|
||||
});
|
||||
});*/
|
||||
return event;
|
||||
}
|
||||
|
||||
@@ -90,14 +96,15 @@ export const eventCreationStore = defineStore('eventStore', {
|
||||
async createEvent() : Promise<string> {
|
||||
try {
|
||||
let event = mapToDto(this.event);
|
||||
let res = await requests.createEvent(event)
|
||||
console.log(JSON.stringify(event));
|
||||
//let res = await requests.createEvent(event)
|
||||
let res = "";
|
||||
if(res) return res;
|
||||
throw new Error("Unable to create event");
|
||||
} catch (error){
|
||||
console.error(error);
|
||||
throw new Error("Unable to post. " + error);
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user