blurgh.
This commit is contained in:
@@ -0,0 +1,18 @@
|
|||||||
|
-- +goose Up
|
||||||
|
-- +goose StatementBegin
|
||||||
|
CREATE TABLE stat (
|
||||||
|
`id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
`scope_id` INT NOT NULL,
|
||||||
|
`name` VARCHAR(255) NOT NULL,
|
||||||
|
`description` TEXT NOT NULL,
|
||||||
|
`weight` FLOAT NOT NULL,
|
||||||
|
`allowed_amounts` JSON,
|
||||||
|
|
||||||
|
UNIQUE (`scope_id`, `name`)
|
||||||
|
);
|
||||||
|
-- +goose StatementEnd
|
||||||
|
|
||||||
|
-- +goose Down
|
||||||
|
-- +goose StatementBegin
|
||||||
|
SELECT 'down SQL query';
|
||||||
|
-- +goose StatementEnd
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
-- +goose Up
|
||||||
|
-- +goose StatementBegin
|
||||||
|
CREATE TABLE IF NOT EXISTS 'project' (
|
||||||
|
`id` INT NOT NULL AUTO_INCREMENT,
|
||||||
|
`scope_id` INT NOT NULL,
|
||||||
|
`author_id` CHAR(36) NOT NULL,
|
||||||
|
`name` VARCHAR(255) NOT NULL,
|
||||||
|
`status` INT NOT NULL,
|
||||||
|
`description` TEXT NOT NULL,
|
||||||
|
|
||||||
|
UNIQUE (`scope_id`, `name`)
|
||||||
|
)
|
||||||
|
-- +goose StatementEnd
|
||||||
|
|
||||||
|
-- +goose Down
|
||||||
|
-- +goose StatementBegin
|
||||||
|
SELECT 'down SQL query';
|
||||||
|
-- +goose StatementEnd
|
||||||
@@ -3,6 +3,12 @@ import type Scope from "$lib/models/scope";
|
|||||||
import type { StatEntry } from "$lib/models/stat";
|
import type { StatEntry } from "$lib/models/stat";
|
||||||
import type Stat from "$lib/models/stat";
|
import type Stat from "$lib/models/stat";
|
||||||
|
|
||||||
|
export class NotFoundError extends Error {
|
||||||
|
constructor(subject: string) {
|
||||||
|
super(`${subject} not found`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export interface Database {
|
export interface Database {
|
||||||
userId: string
|
userId: string
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import type {Pool} from "mysql2/promise";
|
import type {Pool} from "mysql2/promise";
|
||||||
|
|
||||||
import type scope from "$lib/models/scope";
|
import type Scope from "$lib/models/scope";
|
||||||
import type { ScopeEntry, ScopeInput } from "$lib/models/scope";
|
import type { ScopeEntry, ScopeInput } from "$lib/models/scope";
|
||||||
import type { ScopeRepo } from "../interfaces";
|
import type { ScopeRepo } from "../interfaces";
|
||||||
|
|
||||||
@@ -13,8 +13,51 @@ export default class MysqlDBScopes implements ScopeRepo {
|
|||||||
this.userId = userId;
|
this.userId = userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
find(id: number): Promise<scope> {
|
async find(id: number): Promise<Scope> {
|
||||||
throw new Error("Method not implemented.");
|
const [[scopeRows], [projectRows], [statRows]] = await Promise.all([
|
||||||
|
this.connection.execute(`
|
||||||
|
SELECT scope.*, scope_member.name as display_name
|
||||||
|
FROM scope
|
||||||
|
INNER JOIN scope_member ON scope.id = scope_member.scope_id
|
||||||
|
WHERE scope.id = ?
|
||||||
|
`, [id]),
|
||||||
|
this.connection.execute(`
|
||||||
|
SELECT id,name,status
|
||||||
|
FROM project
|
||||||
|
WHERE scope_id = ?
|
||||||
|
`, [id]).catch(() => []),
|
||||||
|
this.connection.execute(`
|
||||||
|
SELECT *
|
||||||
|
FROM stats
|
||||||
|
WHERE scope_id = ?
|
||||||
|
`, [id]).catch(() => []),
|
||||||
|
]);
|
||||||
|
|
||||||
|
console.log(scopeRows, statRows, statRows)
|
||||||
|
|
||||||
|
const r = scopeRows[0] as any;
|
||||||
|
if (!r) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: r.id,
|
||||||
|
name: r.name,
|
||||||
|
abbreviation: r.abbreviation,
|
||||||
|
displayName: r.display_name,
|
||||||
|
projects: ((projectRows||[]) as any[]).map((p:any) => ({
|
||||||
|
id: p.id,
|
||||||
|
name: p.name,
|
||||||
|
status: p.status,
|
||||||
|
})),
|
||||||
|
stats: ((statRows||[]) as any[]).map((s:any) => ({
|
||||||
|
id: s.id,
|
||||||
|
name: s.name,
|
||||||
|
weight: s.weight,
|
||||||
|
description: s.description,
|
||||||
|
allowedAmounts: s.allowed_amounts || void(0),
|
||||||
|
})),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
async list(): Promise<ScopeEntry[]> {
|
async list(): Promise<ScopeEntry[]> {
|
||||||
const [rows] = await this.connection.execute(`
|
const [rows] = await this.connection.execute(`
|
||||||
@@ -31,10 +74,10 @@ export default class MysqlDBScopes implements ScopeRepo {
|
|||||||
displayName: r.display_name,
|
displayName: r.display_name,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
create(input: ScopeInput): Promise<scope> {
|
create(input: ScopeInput): Promise<Scope> {
|
||||||
throw new Error("Method not implemented.");
|
throw new Error("Method not implemented.");
|
||||||
}
|
}
|
||||||
update(id: number, input: Partial<ScopeInput>): Promise<scope> {
|
update(id: number, input: Partial<ScopeInput>): Promise<Scope> {
|
||||||
throw new Error("Method not implemented.");
|
throw new Error("Method not implemented.");
|
||||||
}
|
}
|
||||||
delete(id: number): Promise<void> {
|
delete(id: number): Promise<void> {
|
||||||
|
|||||||
@@ -1,15 +1,10 @@
|
|||||||
import type Item from "./item";
|
|
||||||
import type Scope from "./scope";
|
|
||||||
import type { ScopeEntry } from "./scope";
|
import type { ScopeEntry } from "./scope";
|
||||||
import type { StatAggregate, StatEntry, StatProgressEntry } from "./stat";
|
import type { StatProgressEntry } from "./stat";
|
||||||
import type Stat from "./stat";
|
|
||||||
import type Status from "./status";
|
import type Status from "./status";
|
||||||
|
|
||||||
export default interface Project {
|
export default interface Project extends ProjectEntry {
|
||||||
id: number
|
|
||||||
name: string
|
|
||||||
description: string
|
description: string
|
||||||
status: Status
|
author: string
|
||||||
|
|
||||||
scope: ScopeEntry
|
scope: ScopeEntry
|
||||||
requirements: Requirement[]
|
requirements: Requirement[]
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import type { ProjectEntry } from "./project";
|
|||||||
import type Stat from "./stat";
|
import type Stat from "./stat";
|
||||||
|
|
||||||
export default interface Scope extends ScopeEntry {
|
export default interface Scope extends ScopeEntry {
|
||||||
activeProjects: ProjectEntry[]
|
projects: ProjectEntry[]
|
||||||
stats: Stat[]
|
stats: Stat[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
import type { RequestHandler } from "@sveltejs/kit"
|
import type { RequestHandler } from "@sveltejs/kit";
|
||||||
import Status from "$lib/models/status"
|
|
||||||
import type Scope from "$lib/models/scope"
|
|
||||||
|
|
||||||
export const get: RequestHandler = async({params}) => {
|
import config from "$lib/config";
|
||||||
|
|
||||||
|
export const get: RequestHandler = async({params, locals}) => {
|
||||||
const scopeId = parseInt(params.scope);
|
const scopeId = parseInt(params.scope);
|
||||||
const scope = scopes.find(s => s.id === scopeId);
|
|
||||||
|
const db = await config.database();
|
||||||
|
const scope = await db.withUser(locals.user.id).scopes().find(scopeId)
|
||||||
if (scope === null) {
|
if (scope === null) {
|
||||||
return {
|
return {
|
||||||
status: 404,
|
status: 404,
|
||||||
@@ -27,57 +29,3 @@ export const get: RequestHandler = async({params}) => {
|
|||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const scopes: Scope[] = [
|
|
||||||
{
|
|
||||||
id: 1, name: "3D Modeling", abbreviation: "3D", displayName: "Test",
|
|
||||||
stats: [
|
|
||||||
{id: 101, name: "Asset", weight: 0.1, description: "Some description"},
|
|
||||||
{id: 102, name: "Tweak", weight: 0.2, description: "Some description"},
|
|
||||||
{
|
|
||||||
id: 103, name: "Complexity", weight: 1, description: "Some description",
|
|
||||||
allowedAmounts: {
|
|
||||||
"Basic": 1,
|
|
||||||
"Medium": 3,
|
|
||||||
"Complex": 6,
|
|
||||||
"Excessive": 12,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{id: 104, name: "Hard Surface", weight: 0.4, description: "Some description"},
|
|
||||||
{id: 105, name: "UV Mapping", weight: 0.2, description: "Some description"},
|
|
||||||
{id: 106, name: "Third-Party Asset", weight: 0.1, description: "Some description"},
|
|
||||||
{id: 107, name: "Material", weight: 0.1, description: "Some description"},
|
|
||||||
],
|
|
||||||
activeProjects: [
|
|
||||||
{id: 1001, name: "3D Maps: Proving the Concept", status: Status.Active},
|
|
||||||
{id: 1002, name: "Redrock HQ", status: Status.Active},
|
|
||||||
{id: 1003, name: "Tutorial: Realistic Environments", status: Status.Background},
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 2, name: "Roleplay", abbreviation: "RP", displayName: "Test",
|
|
||||||
stats: [
|
|
||||||
{id: 201, name: "Story", weight: 3, description: "Some description"},
|
|
||||||
{id: 202, name: "Story Word", weight: 0.002, description: "Some description"},
|
|
||||||
{id: 203, name: "Worldbuilding", weight: 0.50, description: "Some description"},
|
|
||||||
{id: 204, name: "Characterbuilding", weight: 0.50, description: "Some description"},
|
|
||||||
{id: 205, name: "Note", weight: 1, description: "Some description"},
|
|
||||||
{id: 206, name: "Wiki Section", weight: 1, description: "Some description"},
|
|
||||||
{id: 207, name: "Wiki Research", weight: 0.5, description: "Some description"},
|
|
||||||
{id: 208, name: "Wiki Complexity", weight: 0.5, description: "Some description"},
|
|
||||||
],
|
|
||||||
activeProjects: [
|
|
||||||
{id: 2001, name: "Ilyna: The Morning After", status: Status.Active},
|
|
||||||
{id: 2002, name: "Renala: Finding Her Voice", status: Status.Active},
|
|
||||||
{id: 2003, name: "General Stories", status: Status.Background},
|
|
||||||
{id: 2004, name: "Uvena: Finish Wiki Page", status: Status.Active},
|
|
||||||
{id: 2005, name: "Va'ynna: Cracking at the Seams", status: Status.Active},
|
|
||||||
{id: 2006, name: "Witch Hunt: Sala's Backlog", status: Status.Active},
|
|
||||||
{id: 2007, name: "Ilyna: Complete Wiki Page", status: Status.Completed},
|
|
||||||
{id: 2008, name: "Renala: Complete Wiki Page", status: Status.Active},
|
|
||||||
]
|
|
||||||
},
|
|
||||||
//{id: 3, name: "Minecraft", abbreviation: "MC"},
|
|
||||||
//{id: 4, name: "Coding", abbreviation: "CODE"},
|
|
||||||
//{id: 5, name: "System Administration", abbreviation: "SA"},
|
|
||||||
]
|
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return {fallthrough: true};
|
||||||
}
|
}
|
||||||
|
|
||||||
const STATUS_ORDER = [
|
const STATUS_ORDER = [
|
||||||
@@ -41,7 +41,7 @@ import MenuItem from "$lib/components/layout/MenuItem.svelte";
|
|||||||
|
|
||||||
export let scope: Scope;
|
export let scope: Scope;
|
||||||
|
|
||||||
let projects = scope.activeProjects;
|
let projects = scope.projects;
|
||||||
let projectsByStatus: Record<Status, ProjectEntry[]>;
|
let projectsByStatus: Record<Status, ProjectEntry[]>;
|
||||||
|
|
||||||
$: projectsByStatus = projects.reduce((p, c) => ({...p, [c.status]: [...p[c.status], c]}), {
|
$: projectsByStatus = projects.reduce((p, c) => ({...p, [c.status]: [...p[c.status], c]}), {
|
||||||
|
|||||||
Reference in New Issue
Block a user