Skip to content

Commit

Permalink
add pack type to search
Browse files Browse the repository at this point in the history
  • Loading branch information
3vorp committed Jan 16, 2024
1 parent 4e34170 commit 2061783
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
4 changes: 3 additions & 1 deletion src/v2/controller/pack.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
Pack,
PackAll,
PackTag,
PackType,
Packs,
} from "../interfaces";

Expand Down Expand Up @@ -42,8 +43,9 @@ export class PackController extends Controller {
@Query() tag?: PackTag,
@Query() name?: string,
@Query() resolution?: number,
@Query() type?: PackType,
): Promise<Packs> {
return this.service.search({ tag, name, resolution });
return this.service.search({ tag, name, resolution, type });
}

/**
Expand Down
15 changes: 9 additions & 6 deletions src/v2/interfaces/packs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ export interface PackGitHub {

export type PackTag = "vanilla" | "faithful" | "classic_faithful" | "jappa" | "progart";

export type PackType = "submission" | "default" | "all";

export interface PackSearch {
tag?: PackTag;
name?: string;
resolution?: number;
type?: PackType;
}

export interface CreationPack {
// either can be specified manually or serialized automatically
id?: string;
Expand All @@ -46,12 +55,6 @@ export interface CreationPackAll extends CreationPack {
submission?: FirstCreationSubmission;
}

export interface PackSearch {
tag?: PackTag;
name?: string;
resolution?: number;
}

export interface Packs extends Array<Pack> {}

export interface FirestormPack extends Pack {
Expand Down
22 changes: 20 additions & 2 deletions src/v2/repository/firestorm/packs.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
FaithfulPack,
CreationPackAll,
PackSearch,
FirestormPack,
} from "~/v2/interfaces";
import { packs } from "../../firestorm";
import SubmissionFirestormRepository from "./submissions.repository";
Expand Down Expand Up @@ -54,7 +55,7 @@ export default class PackFirestormRepository implements PackRepository {
}

search(params: PackSearch): Promise<Packs> {
const { tag, name, resolution } = params;
const { tag, name, resolution, type } = params;
const options: SearchOption<Pack>[] = [];
if (name)
options.push({
Expand All @@ -75,7 +76,24 @@ export default class PackFirestormRepository implements PackRepository {
criteria: "==",
value: resolution,
});
return packs.search(options);
const prom: Promise<FirestormPack[]> = options.length
? packs.search(options)
: packs.readRaw().then(Object.values);

return prom.then(async (packs) => {
if (!type || type === "all") return packs;
const out: Packs = [];
for (const pack of packs) {
try {
await pack.submission();
} catch {
out.push(pack);
}
}

if (type === "default") return out;
return packs.filter((p) => !out.includes(p));
});
}

async renamePack(oldPack: AnyPack, newPack: string): Promise<void> {
Expand Down

0 comments on commit 2061783

Please sign in to comment.