More refactoring
This commit is contained in:
parent
f6bfd285e3
commit
1043d78181
@ -1,10 +1,10 @@
|
||||
'use server'
|
||||
|
||||
|
||||
/* =================================================================================================
|
||||
/** =================================================================================================
|
||||
*
|
||||
* Copyright 2024 Andreas Schaafsma
|
||||
* Purpose: Handle API requests that fetch or permute User data
|
||||
* @author Andreas Schaafsma
|
||||
* @description Handle API requests that fetch or permute User data
|
||||
*
|
||||
* ================================================================================================= */
|
||||
|
||||
@ -14,9 +14,9 @@ import { Attachment, Auth, Bucket, DBState, Post, PostTag, Project, Tag, User, U
|
||||
import { hashpassword } from "@/util/auth";
|
||||
|
||||
|
||||
// Attempt to register a new User
|
||||
/** Attempt to register a new User */
|
||||
async function attemptRegister(request:Request){
|
||||
// Sync db
|
||||
//** Sync db
|
||||
await dbSync;
|
||||
|
||||
// Get request body
|
||||
|
||||
@ -1,15 +1,14 @@
|
||||
import Sequelize, { Association, DataTypes, InferAttributes, InferCreationAttributes, Model, NonAttribute } from "@sequelize/core";
|
||||
import { Attribute, AutoIncrement, NotNull, PrimaryKey, Unique } from "@sequelize/core/decorators-legacy";
|
||||
import { Post } from "./Post";
|
||||
import { Tag } from "./Tag";
|
||||
import { SqliteDialect } from "@sequelize/sqlite3";
|
||||
|
||||
|
||||
class PostTag extends Model<InferAttributes<PostTag>,InferCreationAttributes<PostTag>>
|
||||
{
|
||||
import Sequelize, {
|
||||
InferAttributes,
|
||||
InferCreationAttributes,
|
||||
Model,
|
||||
} from "@sequelize/core";
|
||||
class PostTag extends Model<
|
||||
InferAttributes<PostTag>,
|
||||
InferCreationAttributes<PostTag>
|
||||
> {
|
||||
declare postId: number;
|
||||
declare tagId: number;
|
||||
}
|
||||
|
||||
|
||||
export { PostTag }
|
||||
export { PostTag };
|
||||
|
||||
@ -1,13 +1,30 @@
|
||||
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, PrimaryKey, Unique } from "@sequelize/core/decorators-legacy";
|
||||
import {
|
||||
Association,
|
||||
CreationOptional,
|
||||
DataTypes,
|
||||
InferAttributes,
|
||||
InferCreationAttributes,
|
||||
Model,
|
||||
NonAttribute,
|
||||
} from "@sequelize/core";
|
||||
import {
|
||||
Attribute,
|
||||
AutoIncrement,
|
||||
PrimaryKey,
|
||||
Unique,
|
||||
} from "@sequelize/core/decorators-legacy";
|
||||
import { Post } from "./Post";
|
||||
|
||||
export class Project extends Model<InferAttributes<Project>, InferCreationAttributes<Project>> {
|
||||
@Attribute(DataTypes.INTEGER) @PrimaryKey @Unique @AutoIncrement
|
||||
export class Project extends Model<
|
||||
InferAttributes<Project>,
|
||||
InferCreationAttributes<Project>
|
||||
> {
|
||||
@Attribute(DataTypes.INTEGER)
|
||||
@PrimaryKey
|
||||
@Unique
|
||||
@AutoIncrement
|
||||
declare id: CreationOptional<number>;
|
||||
@Attribute(DataTypes.STRING) @Unique
|
||||
@Attribute(DataTypes.STRING)
|
||||
@Unique
|
||||
declare readableIdentifier: string;
|
||||
@Attribute(DataTypes.STRING)
|
||||
declare name: string;
|
||||
@ -17,5 +34,4 @@ export class Project extends Model<InferAttributes<Project>, InferCreationAttrib
|
||||
declare static associations: {
|
||||
posts: Association<Post, Project>;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -1,10 +1,24 @@
|
||||
import { Association, BelongsToGetAssociationMixin, BelongsToManyGetAssociationsMixin, DataTypes, ForeignKey, InferAttributes, InferCreationAttributes, Model, NonAttribute, Sequelize } from "@sequelize/core";
|
||||
import {
|
||||
Association,
|
||||
BelongsToManyGetAssociationsMixin,
|
||||
DataTypes,
|
||||
InferAttributes,
|
||||
InferCreationAttributes,
|
||||
Model,
|
||||
NonAttribute,
|
||||
} from "@sequelize/core";
|
||||
import { Post } from "./Post";
|
||||
|
||||
import { SqliteDialect } from '@sequelize/sqlite3';
|
||||
import { Attribute, AutoIncrement, BelongsToMany, PrimaryKey, Unique } from "@sequelize/core/decorators-legacy";
|
||||
|
||||
export class Tag extends Model<InferAttributes<Tag>, InferCreationAttributes<Tag>> {
|
||||
import {
|
||||
Attribute,
|
||||
AutoIncrement,
|
||||
PrimaryKey,
|
||||
Unique,
|
||||
} from "@sequelize/core/decorators-legacy";
|
||||
export class Tag extends Model<
|
||||
InferAttributes<Tag>,
|
||||
InferCreationAttributes<Tag>
|
||||
> {
|
||||
@PrimaryKey
|
||||
@AutoIncrement
|
||||
@Attribute(DataTypes.INTEGER)
|
||||
|
||||
@ -1,4 +1,16 @@
|
||||
import { Association, Attributes, CreationAttributes, CreationOptional, DataTypes, HasManyGetAssociationsMixin, HasOneCreateAssociationMixin, HasOneGetAssociationMixin, InferAttributes, InferCreationAttributes, Model, NonAttribute, Sequelize } from "@sequelize/core";
|
||||
import {
|
||||
Association,
|
||||
CreationAttributes,
|
||||
CreationOptional,
|
||||
DataTypes,
|
||||
HasManyGetAssociationsMixin,
|
||||
HasOneCreateAssociationMixin,
|
||||
HasOneGetAssociationMixin,
|
||||
InferAttributes,
|
||||
InferCreationAttributes,
|
||||
Model,
|
||||
NonAttribute,
|
||||
} from "@sequelize/core";
|
||||
import { Post } from "./Post";
|
||||
import { UserPerms } from "./UserPerms";
|
||||
import { Auth } from "./Auth";
|
||||
@ -6,23 +18,20 @@ import {
|
||||
PrimaryKey,
|
||||
Attribute,
|
||||
AutoIncrement,
|
||||
NotNull,
|
||||
BelongsTo,
|
||||
Unique,
|
||||
HasMany,
|
||||
HasOne,
|
||||
UpdatedAt,
|
||||
CreatedAt,
|
||||
} from '@sequelize/core/decorators-legacy';
|
||||
|
||||
import { SqliteDialect } from '@sequelize/sqlite3';
|
||||
} from "@sequelize/core/decorators-legacy";
|
||||
|
||||
type UserCreationAttributes = {
|
||||
username: string;
|
||||
password: string;
|
||||
perms?:Partial<InferAttributes<UserPerms>>
|
||||
}
|
||||
export class User extends Model<InferAttributes<User>, InferCreationAttributes<User>>{
|
||||
perms?: Partial<InferAttributes<UserPerms>>;
|
||||
};
|
||||
export class User extends Model<
|
||||
InferAttributes<User>,
|
||||
InferCreationAttributes<User>
|
||||
> {
|
||||
@Attribute(DataTypes.INTEGER)
|
||||
@PrimaryKey
|
||||
@AutoIncrement
|
||||
@ -34,12 +43,10 @@ export class User extends Model<InferAttributes<User>, InferCreationAttributes<U
|
||||
@Attribute(DataTypes.STRING)
|
||||
declare password: string;
|
||||
|
||||
// Date thingies
|
||||
|
||||
@CreatedAt
|
||||
declare createdAt: CreationOptional<Date>;
|
||||
@UpdatedAt
|
||||
declare updatedAt: CreationOptional<Date>;
|
||||
/** @description The time and date when the object was created */
|
||||
@CreatedAt declare createdAt: CreationOptional<Date>;
|
||||
/** @description The time and date when the object was last modified */
|
||||
@UpdatedAt declare updatedAt: CreationOptional<Date>;
|
||||
|
||||
// Associations
|
||||
declare getAuthTokens: HasManyGetAssociationsMixin<Auth>;
|
||||
@ -48,30 +55,28 @@ export class User extends Model<InferAttributes<User>, InferCreationAttributes<U
|
||||
declare createPerms: HasOneCreateAssociationMixin<UserPerms>;
|
||||
|
||||
/** Defined by {@link Auth.user} */
|
||||
declare authtokens?:NonAttribute<Auth[]>
|
||||
declare authtokens?: NonAttribute<Auth[]>;
|
||||
/** Defined by {@link UserPerms.user} */
|
||||
declare perms?:CreationOptional<CreationAttributes<UserPerms>>
|
||||
declare perms?: CreationOptional<CreationAttributes<UserPerms>>;
|
||||
/** Defined by {@link Post.user} */
|
||||
declare posts?:CreationOptional<Post[]>
|
||||
|
||||
declare posts?: CreationOptional<Post[]>;
|
||||
|
||||
declare static associations: {
|
||||
perms: Association<UserPerms, User>;
|
||||
posts: Association<Post,User>
|
||||
posts: Association<Post, User>;
|
||||
authtokens: Association<Auth, User>;
|
||||
};
|
||||
|
||||
}
|
||||
export function addUserScopes() {
|
||||
User.addScope('defaultScope',{
|
||||
User.addScope("defaultScope", {
|
||||
attributes: {
|
||||
exclude: ['password', 'createdAt', 'updatedAt'],
|
||||
}
|
||||
exclude: ["password", "createdAt", "updatedAt"],
|
||||
},
|
||||
});
|
||||
User.addScope("withPerms", {
|
||||
include: [{ association: "perms" }],
|
||||
});
|
||||
User.addScope("withAuthtokens", {
|
||||
include: [{ association: "authtokens" }],
|
||||
});
|
||||
User.addScope('withPerms',{
|
||||
include: [{association: 'perms' }]
|
||||
})
|
||||
User.addScope('withAuthtokens',{
|
||||
include: [{association: 'authtokens'}]
|
||||
})
|
||||
}
|
||||
@ -1,9 +1,6 @@
|
||||
import { CreationOptional, DataTypes, ForeignKey, InferAttributes, InferCreationAttributes, Model, NonAttribute, Sequelize } from "@sequelize/core";
|
||||
import { User } from "./User";
|
||||
|
||||
import { SqliteDialect } from '@sequelize/sqlite3';
|
||||
import { Attribute, AutoIncrement, BelongsTo, CreatedAt, PrimaryKey, Table, Unique, UpdatedAt } from "@sequelize/core/decorators-legacy";
|
||||
|
||||
@Table({
|
||||
tableName: "Perms"
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user