implemented post management dashboard and started work on projects
This commit is contained in:
+14
-5
@@ -1,9 +1,10 @@
|
||||
import { Association, BelongsToGetAssociationMixin, CreationOptional, DataTypes, ForeignKey, InferAttributes, InferCreationAttributes, Model, NonAttribute, Sequelize } from "@sequelize/core";import { User } from "./User";
|
||||
|
||||
import { SqliteDialect } from '@sequelize/sqlite3';
|
||||
import { Attribute, AutoIncrement, BelongsTo, BelongsToMany, CreatedAt, HasMany, NotNull, PrimaryKey, Unique, UpdatedAt } from "@sequelize/core/decorators-legacy";
|
||||
import { Attribute, AutoIncrement, BelongsTo, BelongsToMany, CreatedAt, Default, HasMany, NotNull, PrimaryKey, Unique, UpdatedAt } from "@sequelize/core/decorators-legacy";
|
||||
import { Tag } from "./Tag";
|
||||
import { PostTag } from "./PostTag";
|
||||
import { Project } from "./Project";
|
||||
|
||||
export class Post extends Model<InferAttributes<Post>, InferCreationAttributes<Post>> {
|
||||
|
||||
@@ -14,9 +15,7 @@ export class Post extends Model<InferAttributes<Post>, InferCreationAttributes<P
|
||||
@AutoIncrement
|
||||
@Unique
|
||||
declare id: CreationOptional<number>;
|
||||
@Attribute(DataTypes.INTEGER)
|
||||
@NotNull
|
||||
declare user_id:ForeignKey<User['id']>;
|
||||
|
||||
@Attribute(DataTypes.STRING)
|
||||
declare title:string
|
||||
@Attribute(DataTypes.STRING)
|
||||
@@ -31,10 +30,19 @@ export class Post extends Model<InferAttributes<Post>, InferCreationAttributes<P
|
||||
|
||||
|
||||
// Associatoins
|
||||
|
||||
@Attribute(DataTypes.INTEGER)
|
||||
@NotNull
|
||||
declare user_id:ForeignKey<User['id']>;
|
||||
|
||||
@Attribute(DataTypes.INTEGER)
|
||||
declare project_id?:CreationOptional<ForeignKey<User['id']>>;
|
||||
|
||||
@BelongsTo(()=>User, { foreignKey: 'user_id', inverse: { type: 'hasMany', as: 'posts' } })
|
||||
declare user:NonAttribute<User>;
|
||||
|
||||
@BelongsTo(()=>Project, { inverse: { type: 'hasMany', as: 'posts' } })
|
||||
declare project:NonAttribute<User>;
|
||||
|
||||
@BelongsToMany(()=>Tag, { through: { model: ()=>PostTag, unique: false}, inverse: {as: 'taggedPosts'} })
|
||||
declare postTags?:NonAttribute<Tag[]>;
|
||||
|
||||
@@ -42,6 +50,7 @@ export class Post extends Model<InferAttributes<Post>, InferCreationAttributes<P
|
||||
|
||||
declare static associations: {
|
||||
user: Association<User, Post>;
|
||||
project: Association<Project, Post>;
|
||||
postTags: Association<Tag, Post>;
|
||||
};
|
||||
}
|
||||
|
||||
+1
-15
@@ -4,20 +4,7 @@ import { SqliteDialect } from '@sequelize/sqlite3';
|
||||
import { Attribute, AutoIncrement, PrimaryKey, Unique } from "@sequelize/core/decorators-legacy";
|
||||
import { Post } from "./Post";
|
||||
|
||||
export type ProjectAttributes = {
|
||||
id: number;
|
||||
title: string;
|
||||
description: string;
|
||||
date: number;
|
||||
user_id:ForeignKey<User['id']>;
|
||||
}
|
||||
export type ProjectCreationAttributes = {
|
||||
title: string;
|
||||
description: string;
|
||||
date: number;
|
||||
user_id:number;
|
||||
}
|
||||
export class Project extends Model<ProjectAttributes, ProjectCreationAttributes> {
|
||||
export class Project extends Model<InferAttributes<Project>, InferCreationAttributes<Project>> {
|
||||
@Attribute(DataTypes.INTEGER) @PrimaryKey @Unique @AutoIncrement
|
||||
declare id: number;
|
||||
@Attribute(DataTypes.STRING) @Unique
|
||||
@@ -27,7 +14,6 @@ export class Project extends Model<ProjectAttributes, ProjectCreationAttributes>
|
||||
|
||||
declare static associations: {
|
||||
posts: Association<Post, Project>;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user