-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from denssle/friends
Add Friends Function
- Loading branch information
Showing
94 changed files
with
2,874 additions
and
1,024 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { FrontendFestivalEvent } from '$lib/models/festivalEvent/FrontendFestivalEvent'; | ||
import { loadFrontEndUserById } from '$lib/services/user-service'; | ||
import { BackendFestivalEvent } from '$lib/models/festivalEvent/BackendFestivalEvent'; | ||
import { Model } from 'sequelize'; | ||
import { | ||
GuestInformationAttributes, | ||
mapToBackendGuestInformation, | ||
mapToFrontendGuestInformation | ||
} from '$lib/db/attributes/GuestInformationAttributes'; | ||
|
||
export type FestivalEventAttributes = { | ||
id: string; | ||
name: string; | ||
description: string; | ||
bringYourOwnBottle: boolean; | ||
bringYourOwnFood: boolean; | ||
location: string; | ||
createdAt: Date; | ||
updatedAt: Date; | ||
startDate: Date; | ||
UserId: string; | ||
GuestInformations: Model<GuestInformationAttributes, any>[]; | ||
}; | ||
|
||
export async function mapToFrontendFestivalEvent(event: FestivalEventAttributes): Promise<FrontendFestivalEvent> { | ||
return { | ||
id: event.id, | ||
name: event.name, | ||
bringYourOwnBottle: event.bringYourOwnBottle, | ||
bringYourOwnFood: event.bringYourOwnFood, | ||
createdAt: event.createdAt, | ||
createdBy: (await loadFrontEndUserById(event.UserId)) ?? null, | ||
description: event.description, | ||
startDate: event.startDate, | ||
location: event.location, | ||
updatedAt: event.updatedAt, | ||
frontendGuestInformation: event.GuestInformations | ||
? await Promise.all( | ||
event.GuestInformations.map((value) => { | ||
return mapToFrontendGuestInformation(value.dataValues); | ||
}) | ||
) | ||
: [] | ||
}; | ||
} | ||
|
||
export async function mapToBackendFestivalEvent(event: FestivalEventAttributes): Promise<BackendFestivalEvent> { | ||
return { | ||
id: event.id, | ||
name: event.name, | ||
bringYourOwnBottle: event.bringYourOwnBottle, | ||
bringYourOwnFood: event.bringYourOwnFood, | ||
createdAt: event.createdAt, | ||
location: event.location, | ||
description: event.description, | ||
startDate: event.startDate, | ||
UserId: event.UserId, | ||
updatedAt: event.updatedAt, | ||
guestInformation: event.GuestInformations.map((value) => { | ||
return mapToBackendGuestInformation(value.dataValues); | ||
}) | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export type FriendAttributes = { | ||
id: string; | ||
friend1Id: string; | ||
friend2Id: string; | ||
createdAt: Date; | ||
updatedAt: Date; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { loadFrontEndUserById } from '$lib/services/user-service'; | ||
import { FriendRequestData } from '$lib/models/updates/FriendRequestData'; | ||
|
||
export type FriendRequestAttributes = { | ||
id: string; | ||
senderId: string; | ||
receiverId: string; | ||
createdAt: Date; | ||
updatedAt: Date; | ||
}; | ||
|
||
export async function convertToFriendRequest(attribute: FriendRequestAttributes): Promise<FriendRequestData> { | ||
return { | ||
id: attribute.id, | ||
receivedFrom: await loadFrontEndUserById(attribute.receiverId), | ||
sendTo: await loadFrontEndUserById(attribute.senderId) | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { BackendGuestInformation } from '$lib/models/guestInformation/BackendGuestInformation'; | ||
import { FrontendGuestInformation } from '$lib/models/guestInformation/FrontendGuestInformation'; | ||
import { loadFrontEndUserById } from '$lib/services/user-service'; | ||
|
||
export type GuestInformationAttributes = { | ||
id: string; | ||
festivalEventId: string; | ||
food: string; | ||
drink: string; | ||
numberOfOtherGuests: number; | ||
coming: boolean; | ||
comment: string; | ||
createdAt: Date; | ||
updatedAt: Date; | ||
FestivalEventId: string; | ||
UserId: string; | ||
}; | ||
|
||
export async function mapToFrontendGuestInformation( | ||
dataValues: GuestInformationAttributes | ||
): Promise<FrontendGuestInformation> { | ||
return { | ||
coming: dataValues.coming, | ||
numberOfOtherGuests: dataValues.numberOfOtherGuests, | ||
drink: dataValues.drink, | ||
comment: dataValues.comment, | ||
food: dataValues.food, | ||
user: await loadFrontEndUserById(dataValues.UserId) | ||
}; | ||
} | ||
|
||
export function mapToBackendGuestInformation(dataValues: GuestInformationAttributes): BackendGuestInformation { | ||
return { | ||
UserId: dataValues.UserId, | ||
FestivalEventId: dataValues.festivalEventId, | ||
food: dataValues.food, | ||
comment: dataValues.comment, | ||
drink: dataValues.drink, | ||
numberOfOtherGuests: dataValues.numberOfOtherGuests, | ||
coming: dataValues.coming | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export interface SessionTokenAttributes { | ||
token: string; | ||
UserId: string; | ||
createdAt: Date; | ||
updatedAt: Date; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import type { BackendUser } from '$lib/models/user/BackendUser'; | ||
|
||
export type UserAttributes = { | ||
id: string; | ||
password: string; | ||
nickname: string; | ||
forename: string; | ||
lastname: string; | ||
email: string; | ||
createdAt: Date; | ||
updatedAt: Date; | ||
}; | ||
|
||
export function convertToBackendUser(dataValues: UserAttributes): BackendUser { | ||
return { | ||
id: dataValues.id, | ||
email: dataValues.email, | ||
nickname: dataValues.nickname, | ||
forename: dataValues.forename, | ||
lastname: dataValues.lastname, | ||
updatedAt: dataValues.updatedAt, | ||
createdAt: dataValues.createdAt, | ||
password: dataValues.password | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export type UserImageAttributes = { | ||
id: string; | ||
UserId: string; | ||
image: Buffer; | ||
createdAt: Date; | ||
updatedAt: Date; | ||
}; |
Oops, something went wrong.