Add models

This commit is contained in:
Alex Piqueras 2024-12-02 09:45:35 +01:00
parent d7149bc5d9
commit 0140d93b9a
3 changed files with 146 additions and 0 deletions

View File

@ -0,0 +1,58 @@
import { Model, Table, Column, DataType } from "sequelize-typescript";
import Hotel from "./hotel.model.ts";
import Client from "./client.model.ts";
@Table({
tableName: "HotelBooking",
})
export default class Booking extends Model {
@Unique
@Column({
type: DataType.INTEGER,
primaryKey: true,
autoIncrement: true,
field: "id"
})
id: number;
@ForeignKey(() => Hotel)
@Column({
type: DataType.INTEGER,
field: "HotelId"
})
hotelId: number;
@BelongsTo(() => Hotel)
hotel: Hotel;
@Column({
type: DataType.STRING(255),
field: "Name"
})
name?: string;
@Column({
type: DataType.STRING(255),
field: "Address"
})
address?: string;
@Column({
type: DataType.DATE,
field: "CreatedDate"
defaultValue: DataType.NOW
})
createdDate: Date;
@ForeignKey(() => Client)
@Column({
type: DataType.INTEGER,
field: "clientId"
})
clientId: number;
@BelongsTo(() => Client)
client: Client;
}

View File

@ -0,0 +1,47 @@
import { Model, Table, Column, DataType } from "sequelize-typescript";
import Hotel from "./hotel.model.ts";
import Booking from "./booking.model.ts";
@Table({
tableName: "Client",
})
export default class Client extends Model {
@Unique
@Column({
type: DataType.INTEGER,
primaryKey: true,
autoIncrement: true,
field: "id"
})
id: number;
@Column({
type: DataType.STRING(255),
field: "Name"
})
name: string;
@Column({
type: DataType.STRING(255),
field: "Address"
})
address: string;
@Column({
type: DataType.STRING(255),
field: "Phone"
})
phone: string;
@Column({
type: DataType.DATE,
field: "CreatedDate"
defaultValue: DataType.NOW
})
createdDate: Date;
@HasMany(() => Booking)
bookings: Booking[];
}

41
src/models/hotel.model.ts Normal file
View File

@ -0,0 +1,41 @@
import { Model, Table, Column, DataType } from "sequelize-typescript";
import Client from "./client.model.ts";
import Booking from "./booking.model.ts";
@Table({
tableName: "Hotel",
})
export default class Hotel extends Model {
@Unique
@Column({
type: DataType.INTEGER,
primaryKey: true,
autoIncrement: true,
field: "id"
})
id: number;
@Column({
type: DataType.STRING(255),
field: "Name"
})
name: string;
@Column({
type: DataType.STRING(255),
field: "Address"
})
address: string;
@Column({
type: DataType.DATE,
field: "CreatedDate"
defaultValue: DataType.NOW
})
createdDate: Date;
@HasMany(() => Booking)
bookings: Booking[];
}