feature/#22-API-Tokens #49

Merged
jkeffects merged 8 commits from feature/#22-API-Tokens into develop 2025-01-22 10:59:46 +00:00
3 changed files with 14 additions and 9 deletions
Showing only changes of commit ca6dbafaf1 - Show all commits

View file

@ -2,7 +2,10 @@ import { Column, CreateDateColumn, Entity, PrimaryColumn } from "typeorm";
@Entity() @Entity()
export class api { export class api {
@PrimaryColumn({ type: "varchar", length: 255 }) @PrimaryColumn({ generated: "increment", type: "int" })
id: number;
@Column({ type: "varchar", length: 255, unique: true, select: false })
token: string; token: string;
@Column({ type: "varchar", length: 255 }) @Column({ type: "varchar", length: 255 })

View file

@ -5,7 +5,7 @@ import { api } from "./api";
@Entity() @Entity()
export class apiPermission { export class apiPermission {
@PrimaryColumn({ type: "int" }) @PrimaryColumn({ type: "int" })
apiToken: number; apiId: number;
@PrimaryColumn({ type: "varchar", length: 255 }) @PrimaryColumn({ type: "varchar", length: 255 })
permission: PermissionString; permission: PermissionString;

View file

@ -11,11 +11,12 @@ export class AddApiTokens1737453096674 implements MigrationInterface {
new Table({ new Table({
name: "api", name: "api",
columns: [ columns: [
{ name: "token", type: "varchar", length: "255", isPrimary: true, isNullable: false }, { name: "id", type: variableType_int, isPrimary: true, isNullable: false },
{ name: "token", type: "varchar", length: "255", isUnique: true, isNullable: false },
{ name: "title", type: "varchar", length: "255", isNullable: false }, { name: "title", type: "varchar", length: "255", isNullable: false },
{ name: "createdAt", type: "datetime", default: "CURRENT_TIMESTAMP(6)", isNullable: false }, { name: "createdAt", type: "datetime", default: "CURRENT_TIMESTAMP(6)", isNullable: false },
{ name: "lastUsage", type: "datetime", isNullable: true }, { name: "lastUsage", type: "datetime", isNullable: true, default: null },
{ name: "expiry", type: "datetime", isNullable: true }, { name: "expiry", type: "datetime", isNullable: true, default: null },
], ],
}), }),
true true
@ -25,17 +26,18 @@ export class AddApiTokens1737453096674 implements MigrationInterface {
new Table({ new Table({
name: "api_permission", name: "api_permission",
columns: [ columns: [
{ name: "apiToken", type: "varchar", length: "255", isPrimary: true, isNullable: false }, { name: "apiId", type: variableType_int, isPrimary: true, isNullable: false },
{ name: "permission", type: "varchar", length: "255", isPrimary: true, isNullable: false }, { name: "permission", type: "varchar", length: "255", isPrimary: true, isNullable: false },
], ],
}) }),
true
); );
await queryRunner.createForeignKey( await queryRunner.createForeignKey(
"api_permission", "api_permission",
new TableForeignKey({ new TableForeignKey({
columnNames: ["apiToken"], columnNames: ["apiId"],
referencedColumnNames: ["token"], referencedColumnNames: ["id"],
referencedTableName: "api", referencedTableName: "api",
onDelete: "CASCADE", onDelete: "CASCADE",
onUpdate: "RESTRICT", onUpdate: "RESTRICT",