diff --git a/components/Event.vue b/components/Event.vue new file mode 100644 index 00000000..a322ea76 --- /dev/null +++ b/components/Event.vue @@ -0,0 +1,44 @@ + + diff --git a/pages/e/[slug].vue b/pages/event/[slug].vue similarity index 100% rename from pages/e/[slug].vue rename to pages/event/[slug].vue diff --git a/pages/index.vue b/pages/index.vue index f51d4d04..cc868342 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -19,8 +19,7 @@ import type { Announcement, Event } from '#build/types/nitro-imports' - {{ event.title }} - + diff --git a/server/api/events/index.get.ts b/server/api/events/index.get.ts index 5ecb8cd0..071f2a16 100644 --- a/server/api/events/index.get.ts +++ b/server/api/events/index.get.ts @@ -1,6 +1,6 @@ -import { Event } from "~/server/utils/sequelize" +import { Event, Place, Tag } from "~/server/utils/sequelize" export default defineEventHandler((event) => { - return Event.findAll() + return Event.findAll({ include: [Place, Tag] }) }) \ No newline at end of file diff --git a/server/utils/sequelize.ts b/server/utils/sequelize.ts index 2dc3183f..fa06b798 100644 --- a/server/utils/sequelize.ts +++ b/server/utils/sequelize.ts @@ -28,6 +28,9 @@ import { Index, Unique, BeforeSave, + AllowNull, + BelongsToMany, + BelongsTo, } from "@sequelize/core/decorators-legacy" // import type { SqliteDialect } from "@sequelize/sqlite3"; @@ -94,12 +97,73 @@ InferCreationAttributes @Attribute(DataTypes.TEXT) declare description: string + @Attribute({ + type: DataTypes.INTEGER.UNSIGNED, + references: { table: "places", key: "id" }, + onUpdate: "CASCADE", + onDelete: "CASCADE", + }) + declare placeId: number; + + // @BelongsTo(() => Place, 'id') + // declare places + + @BelongsToMany(() => Tag, { through: 'event_tags '}) + declare tags?: NonAttribute + +} + +@Table({ + tableName: 'tags' +}) +export class Tag extends Model< +InferAttributes, +InferCreationAttributes +> { + @Attribute(DataTypes.STRING) + @Index + @Unique + declare tag: string; + + // @BelongsToMany(() => Event, { through: 'event_tags' }) + // declare events?: NonAttribute +} + +@Table({ + tableName: 'places' +}) +export class Place extends Model< + InferAttributes, + InferCreationAttributes +> { + @Attribute(DataTypes.INTEGER.UNSIGNED) + @PrimaryKey + @AutoIncrement + declare readonly id: CreationOptional; + + @Attribute(DataTypes.STRING) + @Index + @Unique + declare name: string; + + @Attribute(DataTypes.STRING) + declare address: string; + + @Attribute(DataTypes.FLOAT) + declare latitude: number; + + @Attribute(DataTypes.FLOAT) + declare longitude: number; + + @HasMany(() => Event, /* foreign key */ 'placeId') + declare events?: NonAttribute; + } type Role = "admin" | "editor" | "user" @Table({ - tableName: "Users", + tableName: "users", indexes: [{ fields: ["email"], unique: true }], }) export class User extends Model< @@ -214,4 +278,4 @@ type Role = "admin" | "editor" | "user" // declare author?: NonAttribute; // } -sequelize.addModels([Announcement, Event]); \ No newline at end of file +sequelize.addModels([Announcement, Place, Event, Tag]); \ No newline at end of file