You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
112 lines
2.7 KiB
TypeScript
112 lines
2.7 KiB
TypeScript
//
|
|
// Prelude
|
|
//
|
|
|
|
type Natural = number
|
|
type Integer = number
|
|
type Rational = [number, number]
|
|
type Real = number
|
|
|
|
type Datetime = string
|
|
type Time = string
|
|
|
|
type Maybe<T> = { present: false } | { present: true; value: T }
|
|
|
|
//
|
|
// PostiDM
|
|
//
|
|
|
|
type UserID = string
|
|
type BookingID = string
|
|
type SlotID = string
|
|
type SeatID = string
|
|
type RoomID = string
|
|
|
|
type UserPermission = 'basic' | 'helper' | 'moderator' | 'admin'
|
|
|
|
type PostiDM = {
|
|
users: Map<UserID, User>
|
|
rooms: Map<RoomID, Room>
|
|
seats: Map<SeatID, Seat>
|
|
|
|
slots: Map<SlotID, Slot>
|
|
getCurrentWeekSlots(): Slot[]
|
|
|
|
bookings: Map<BookingID, Booking>
|
|
}
|
|
|
|
// TODO: Tutte le funzioni "getCurrentSomething()" in realtà sono da pensare meglio in modo da poter passare un range temporale o qualcosa del genere
|
|
|
|
/**
|
|
* Un utente loggato con credenziali di ateneo
|
|
*/
|
|
type User = {
|
|
id: UserID
|
|
permissions: Set<UserPermission>
|
|
|
|
getBookings(): Booking[]
|
|
getCurrentSeat(): Maybe<Seat>
|
|
}
|
|
|
|
/**
|
|
* Una prenotazione di un utente per un certo slot orario
|
|
*/
|
|
type Booking = {
|
|
id: BookingID
|
|
timestamp: Datetime
|
|
slotID: SlotID
|
|
userID: UserID // cioè ok c'è User.bookings però pensando in SQL è sempre meglio avere comunque un id qui (forse)
|
|
|
|
getSlot(): Slot // giusto per comodità per parlare direttamente dell'oggetto "Slot" relativo ad un "Booking"
|
|
getSeat(): Seat // ".getSlot().getSeat()"
|
|
}
|
|
|
|
/**
|
|
* Slot rappresenta uno slot orario prenotabile per un certo posto
|
|
*/
|
|
type Slot = {
|
|
id: SlotID
|
|
seatID: SeatID
|
|
// Magari invece di eliminare uno slot, in quanto ricrearlo potrebbe essere complicato e forse è meglio che i moderatori semplicemente disabilitino uno slot se vogliono non renderlo prenotabile (?)
|
|
// disabled: boolean
|
|
range: {
|
|
from: Datetime
|
|
to: Datetime
|
|
}
|
|
|
|
getCurrentBooking(): Maybe<Booking>
|
|
}
|
|
|
|
/**
|
|
* Seat rappresenta un posto in dipartimento in una certa stanza
|
|
*/
|
|
type Seat = {
|
|
id: SeatID
|
|
diagram: {
|
|
x: Natural
|
|
y: Natural
|
|
width: Natural
|
|
height: Natural
|
|
}
|
|
|
|
// TODO: Forse per ora è meglio fare che più utenti possono prenotare lo stesso posto così inizialmente possiamo fare che in ogni stanza c'è solo un posto e la gente può prenotarsi solo "alla stanza" e non al posto specifico, altrimenti facciamo "getCurrentBookedUser(): Maybe<User>"
|
|
getCurrentlyBookedUsers(): User[]
|
|
getRoom(): Room
|
|
}
|
|
|
|
/**
|
|
* Room rappresenta una stanza in dipartimento e contiene dei posti
|
|
*/
|
|
type Room = {
|
|
id: RoomID
|
|
name: string
|
|
diagram: {
|
|
gridRows: Natural
|
|
gridCols: Natural
|
|
}
|
|
|
|
getSeats(): Seat[]
|
|
getTotalSeatCount(): Natural // ".seatIDs.length"
|
|
getCurrentBookedSeatCount(): Natural
|
|
}
|