Resolved merge conflict on new changes
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import { Sequelize, DataTypes, Optional, Model, UUIDV4 } from 'sequelize';
|
||||
import { MPost } from '@/model/sequelize/Post';
|
||||
const sequelize = new Sequelize({
|
||||
dialect: 'sqlite',
|
||||
storage: 'db.sqlite'
|
||||
});
|
||||
interface AttachmentAttributes{
|
||||
id: string;
|
||||
path: string;
|
||||
post_id: number;
|
||||
};
|
||||
interface AttachmentCreationAttributes extends Optional<AttachmentAttributes, 'id'>{};
|
||||
class AttachmentModel extends Model<AttachmentAttributes, AttachmentCreationAttributes>{
|
||||
id:string = "";
|
||||
path:string = "";
|
||||
post_id:number|undefined;
|
||||
createdAt?: Date;
|
||||
updatedAt?: Date;
|
||||
// declare title
|
||||
}
|
||||
export const MAttachment = sequelize.define<AttachmentModel>(
|
||||
'Attachment',
|
||||
{
|
||||
id: {
|
||||
allowNull: false,
|
||||
autoIncrement: false,
|
||||
type: DataTypes.UUID,
|
||||
defaultValue: UUIDV4,
|
||||
primaryKey: true,
|
||||
unique: true,
|
||||
},
|
||||
path: {
|
||||
type: DataTypes.STRING,
|
||||
},
|
||||
post_id: {
|
||||
type: DataTypes.INTEGER,
|
||||
key: "Post"
|
||||
}
|
||||
}
|
||||
);
|
||||
MAttachment.hasOne(MPost);
|
||||
+50
-15
@@ -1,22 +1,37 @@
|
||||
import { Sequelize, DataTypes, Optional, Model, UUIDV4 } from 'sequelize';
|
||||
// import { Sequelize, DataTypes, Optional, Model, UUIDV4 } from 'sequelize';
|
||||
import {
|
||||
Association, DataTypes, HasManyAddAssociationMixin, HasManyCountAssociationsMixin,
|
||||
HasManyCreateAssociationMixin, HasManyGetAssociationsMixin, HasManyHasAssociationMixin,
|
||||
HasManySetAssociationsMixin, HasManyAddAssociationsMixin, HasManyHasAssociationsMixin,
|
||||
HasManyRemoveAssociationMixin, HasManyRemoveAssociationsMixin, Model, ModelDefined, Optional,
|
||||
Sequelize, InferAttributes, InferCreationAttributes, CreationOptional, NonAttribute, ForeignKey, BelongsTo, BelongsToGetAssociationMixin, UUIDV4, UUID
|
||||
} from 'sequelize';
|
||||
|
||||
import { MUser, UserModel } from '@/model/sequelize/User';
|
||||
const sequelize = new Sequelize({
|
||||
dialect: 'sqlite',
|
||||
storage: 'db.sqlite'
|
||||
});
|
||||
interface AuthAttributes{
|
||||
id: number;
|
||||
token: string;
|
||||
user_id: number;
|
||||
};
|
||||
interface AuthCreationAttributes extends Optional<Optional<AuthAttributes, 'id'>,'token'> {};
|
||||
class AuthModel extends Model<AuthAttributes, AuthCreationAttributes>{
|
||||
createdAt?: Date;
|
||||
updatedAt?: Date;
|
||||
token: any;
|
||||
// declare title
|
||||
// interface AuthAttributes{
|
||||
// id: number;
|
||||
// token: string;
|
||||
// user_id: number;
|
||||
// };
|
||||
// interface AuthCreationAttributes extends Optional<Optional<AuthAttributes, 'id'>,'token'> {};
|
||||
// class AuthModel extends Model<AuthAttributes, AuthCreationAttributes>{
|
||||
// createdAt?: Date;
|
||||
// updatedAt?: Date;
|
||||
// token: any;
|
||||
// // declare title
|
||||
// }
|
||||
class AuthModel extends Model<InferAttributes<AuthModel, { omit: 'user' }>, InferCreationAttributes<AuthModel, { omit: 'user' }>> {
|
||||
declare id: CreationOptional<number>;
|
||||
declare token: CreationOptional<string>;
|
||||
declare user_id: number;
|
||||
declare getUser: BelongsToGetAssociationMixin<UserModel>;
|
||||
declare user:NonAttribute<UserModel>;
|
||||
}
|
||||
export const MAuth = sequelize.define<AuthModel>(
|
||||
'Auth',
|
||||
export const MAuth = AuthModel.init(
|
||||
{
|
||||
id: {
|
||||
allowNull: false,
|
||||
@@ -34,5 +49,25 @@ export const MAuth = sequelize.define<AuthModel>(
|
||||
key: "User"
|
||||
}
|
||||
// date: DataTypes.DATE,
|
||||
},
|
||||
{
|
||||
tableName: 'Auths',
|
||||
sequelize // passing the `sequelize` instance is required
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
MAuth.belongsTo(MUser, {
|
||||
foreignKey:'user_id',
|
||||
targetKey:'id',
|
||||
as: 'user'
|
||||
})
|
||||
|
||||
MUser.hasMany(MAuth, {
|
||||
sourceKey: 'id',
|
||||
foreignKey: 'user_id',
|
||||
as: 'authtokens' // this determines the name in `associations`!
|
||||
});
|
||||
// MAuth.belongsTo(MUser, { targetKey: 'id' });
|
||||
// MAuth.sync();
|
||||
|
||||
export { AuthModel }
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Sequelize, DataTypes, Optional, Model } from 'sequelize';
|
||||
import { MAttachment } from '@/model/sequelize/Attachment';
|
||||
const sequelize = new Sequelize({
|
||||
dialect: 'sqlite',
|
||||
storage: 'db.sqlite'
|
||||
@@ -29,4 +30,5 @@ export const MPost = sequelize.define<PostModel>(
|
||||
title: DataTypes.STRING,
|
||||
content: DataTypes.STRING,
|
||||
}
|
||||
);
|
||||
);
|
||||
MPost.hasMany(MAttachment);
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
import { BelongsToGetAssociationMixin, UUIDV4 } from 'sequelize';
|
||||
import {
|
||||
Association, DataTypes, HasManyAddAssociationMixin, HasManyCountAssociationsMixin,
|
||||
HasManyCreateAssociationMixin, HasManyGetAssociationsMixin, HasManyHasAssociationMixin,
|
||||
HasManySetAssociationsMixin, HasManyAddAssociationsMixin, HasManyHasAssociationsMixin,
|
||||
HasManyRemoveAssociationMixin, HasManyRemoveAssociationsMixin, Model, ModelDefined, Optional,
|
||||
Sequelize, InferAttributes, InferCreationAttributes, CreationOptional, NonAttribute, ForeignKey,
|
||||
} from 'sequelize';
|
||||
import { UserModel } from '@/model/sequelize/User';
|
||||
|
||||
const sequelize = new Sequelize({
|
||||
dialect: 'sqlite',
|
||||
storage: 'db.sqlite'
|
||||
});
|
||||
class ResourceModel extends Model<InferAttributes<ResourceModel, { omit: 'owner' }>, InferCreationAttributes<ResourceModel, { omit: 'owner' }>>{
|
||||
declare id: CreationOptional<string>;
|
||||
declare path: string;
|
||||
declare owner: NonAttribute<UserModel>;
|
||||
declare getOwner: BelongsToGetAssociationMixin<UserModel>;
|
||||
|
||||
// user_id: number | undefined;
|
||||
createdAt?: Date;
|
||||
updatedAt?: Date;
|
||||
// declare title
|
||||
declare static associations: {
|
||||
owner: Association<ResourceModel,UserModel>;
|
||||
};
|
||||
}
|
||||
|
||||
ResourceModel.init({
|
||||
id: {
|
||||
allowNull: false,
|
||||
autoIncrement: false,
|
||||
type: DataTypes.UUID,
|
||||
defaultValue: UUIDV4,
|
||||
primaryKey: true,
|
||||
unique: true,
|
||||
},
|
||||
path: {
|
||||
type: DataTypes.STRING
|
||||
},
|
||||
createdAt: {
|
||||
type: DataTypes.DATE
|
||||
},
|
||||
updatedAt: {
|
||||
type: DataTypes.DATE
|
||||
}
|
||||
},{
|
||||
sequelize,
|
||||
tableName: 'Resource'
|
||||
});
|
||||
// export const MResource = sequelize.define<ResourceModel>(
|
||||
// 'Resource',
|
||||
// {
|
||||
// id: {
|
||||
// allowNull: false,
|
||||
// autoIncrement: false,
|
||||
// type: DataTypes.UUID,
|
||||
// defaultValue: UUIDV4,
|
||||
// primaryKey: true,
|
||||
// unique: true,
|
||||
// },
|
||||
// path: {
|
||||
// type: DataTypes.STRING,
|
||||
// },
|
||||
// user_id: {
|
||||
// type: DataTypes.INTEGER,
|
||||
// key: "User"
|
||||
// }
|
||||
// }
|
||||
// );
|
||||
// UserModel.hasMany(MResource);
|
||||
// ResourceModel.belongsTo(UserModel);
|
||||
+38
-17
@@ -1,24 +1,40 @@
|
||||
import { Sequelize, DataTypes, Optional, Model } from 'sequelize';
|
||||
// import { Sequelize, DataTypes, Optional, Model } from 'sequelize';
|
||||
import {
|
||||
Association, DataTypes, HasManyAddAssociationMixin, HasManyCountAssociationsMixin,
|
||||
HasManyCreateAssociationMixin, HasManyGetAssociationsMixin, HasManyHasAssociationMixin,
|
||||
HasManySetAssociationsMixin, HasManyAddAssociationsMixin, HasManyHasAssociationsMixin,
|
||||
HasManyRemoveAssociationMixin, HasManyRemoveAssociationsMixin, Model, ModelDefined, Optional,
|
||||
Sequelize, InferAttributes, InferCreationAttributes, CreationOptional, NonAttribute, ForeignKey, BelongsTo, BelongsToGetAssociationMixin, UUIDV4, UUID
|
||||
} from 'sequelize';
|
||||
|
||||
import { AuthModel } from '@/model/sequelize/Auth';
|
||||
|
||||
const sequelize = new Sequelize({
|
||||
dialect: 'sqlite',
|
||||
storage: 'db.sqlite'
|
||||
});
|
||||
interface UserAttributes{
|
||||
id: number;
|
||||
username: string;
|
||||
password: string;
|
||||
};
|
||||
interface UserCreationAttributes extends Optional<UserAttributes, 'id'>{};
|
||||
class UserModel extends Model<UserAttributes, UserCreationAttributes>{
|
||||
createdAt?: Date;
|
||||
updatedAt?: Date;
|
||||
username: string = "";
|
||||
password: string = "";
|
||||
id?:number;
|
||||
// declare title
|
||||
// interface UserAttributes{
|
||||
// id: number;
|
||||
// username: string;
|
||||
// password: string;
|
||||
// };
|
||||
// interface UserCreationAttributes extends Optional<UserAttributes, 'id'>{};
|
||||
// export class UserModel extends Model<UserAttributes, UserCreationAttributes>{
|
||||
// createdAt?: Date;
|
||||
// updatedAt?: Date;
|
||||
// username: string = "";
|
||||
// password: string = "";
|
||||
// id?:number;
|
||||
// // declare title
|
||||
// }
|
||||
export class UserModel extends Model<InferAttributes<UserModel>, InferCreationAttributes<UserModel>>{
|
||||
declare id: number|null;
|
||||
declare username: string;
|
||||
declare password: string;
|
||||
declare getAuths:HasManyGetAssociationsMixin<AuthModel>;
|
||||
}
|
||||
export const MUser = sequelize.define<UserModel>(
|
||||
'User',
|
||||
|
||||
export const MUser = UserModel.init(
|
||||
{
|
||||
id: {
|
||||
allowNull: false,
|
||||
@@ -35,5 +51,10 @@ export const MUser = sequelize.define<UserModel>(
|
||||
allowNull: false,
|
||||
type: DataTypes.STRING,
|
||||
}
|
||||
},
|
||||
{
|
||||
tableName: 'Users',
|
||||
sequelize // passing the `sequelize` instance is required
|
||||
}
|
||||
);
|
||||
);
|
||||
MUser.sync();
|
||||
Reference in New Issue
Block a user