mirror of
https://github.com/djhackersdev/minime.git
synced 2026-04-22 01:07:24 -05:00
idz: Add idz_weekly_missions table
This commit is contained in:
parent
c2fbb0ddff
commit
d19f1ac004
|
|
@ -265,3 +265,16 @@ create table "idz_team_reservation" (
|
|||
"join_time" timestamp not null,
|
||||
"leader" boolean not null
|
||||
);
|
||||
|
||||
create table "idz_weekly_missions" (
|
||||
"id" integer primary key not null
|
||||
references "idz_profile"("id")
|
||||
on delete cascade,
|
||||
"weekly_reset" timestamp not null,
|
||||
"mission_left" integer not null,
|
||||
"progress_left" integer not null,
|
||||
"params_left" integer not null,
|
||||
"mission_right" integer not null,
|
||||
"progress_right" integer not null,
|
||||
"params_right" integer not null
|
||||
);
|
||||
|
|
|
|||
|
|
@ -29,6 +29,19 @@ create table "idz_stamp_unlock" (
|
|||
constraint "idz_stamp_unlock_uq" unique ("profile_id", "stamp_no")
|
||||
);
|
||||
|
||||
create table "idz_weekly_missions" (
|
||||
"id" integer primary key not null
|
||||
references "idz_profile"("id")
|
||||
on delete cascade,
|
||||
"weekly_reset" timestamp not null,
|
||||
"mission_left" integer not null,
|
||||
"progress_left" integer not null,
|
||||
"params_left" integer not null,
|
||||
"mission_right" integer not null,
|
||||
"progress_right" integer not null,
|
||||
"params_right" integer not null
|
||||
);
|
||||
|
||||
insert into "new_idz_settings" (
|
||||
"id",
|
||||
"music",
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ export async function loadProfile(
|
|||
const team = teamId && (await w.teams().load(teamId));
|
||||
const stamps = await w.stamps().loadAll(profileId);
|
||||
const selectedStamps = await w.stamps().loadSelection(profileId);
|
||||
const weeklyMissions = await w.weeklyMissions().load(profileId);
|
||||
|
||||
return {
|
||||
type: "load_profile_res",
|
||||
|
|
@ -55,5 +56,6 @@ export async function loadProfile(
|
|||
tickets,
|
||||
stamps,
|
||||
selectedStamps,
|
||||
weeklyMissions,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,3 +17,4 @@ export { Team, TeamAuto, TeamMember } from "./team";
|
|||
export { Tickets } from "./tickets";
|
||||
export { TimeAttackScore } from "./timeAttack";
|
||||
export { Unlocks } from "./unlocks";
|
||||
export { WeeklyMissions } from "./weeklyMissions";
|
||||
|
|
|
|||
9
src/idz/userdb/model/weeklyMissions.ts
Normal file
9
src/idz/userdb/model/weeklyMissions.ts
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
export interface WeeklyMissions {
|
||||
weeklyReset: Date;
|
||||
weeklyMissionLeft: number;
|
||||
weeklyProgressLeft: number;
|
||||
weeklyParamsLeft: number;
|
||||
weeklyMissionRight: number;
|
||||
weeklyProgressRight: number;
|
||||
weeklyParamsRight: number;
|
||||
}
|
||||
|
|
@ -156,6 +156,15 @@ export interface TimeAttackRepository {
|
|||
): Promise<void>;
|
||||
}
|
||||
|
||||
export interface WeeklyMissionsRepository {
|
||||
load(profileId: Id<Model.Profile>): Promise<Model.WeeklyMissions>;
|
||||
|
||||
save(
|
||||
profileId: Id<Model.Profile>,
|
||||
weeklyMissions: Model.WeeklyMissions
|
||||
): Promise<void>;
|
||||
}
|
||||
|
||||
export interface Repositories {
|
||||
backgrounds(): FlagRepository<Model.BackgroundCode>;
|
||||
|
||||
|
|
@ -192,4 +201,6 @@ export interface Repositories {
|
|||
titles(): FlagRepository<Model.TitleCode>;
|
||||
|
||||
unlocks(): FacetRepository<Model.Unlocks>;
|
||||
|
||||
weeklyMissions(): WeeklyMissionsRepository;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import { SelectedStamps } from "../model/stamps";
|
|||
import { Story } from "../model/story";
|
||||
import { Tickets } from "../model/tickets";
|
||||
import { Unlocks } from "../model/unlocks";
|
||||
import { WeeklyMissions } from "../model/weeklyMissions";
|
||||
import { AimeId } from "../../../model";
|
||||
|
||||
export interface SaveProfileRequest {
|
||||
|
|
@ -29,4 +30,5 @@ export interface SaveProfileRequest {
|
|||
settings: Settings;
|
||||
selectedStamps?: SelectedStamps;
|
||||
stamps?: Set<StampCode>;
|
||||
weeklyMissions?: WeeklyMissions;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import { Story } from "../model/story";
|
|||
import { Tickets } from "../model/tickets";
|
||||
import { TimeAttackScore } from "../model/timeAttack";
|
||||
import { Unlocks } from "../model/unlocks";
|
||||
import { WeeklyMissions } from "../model/weeklyMissions";
|
||||
import { AimeId } from "../../../model";
|
||||
|
||||
export interface LoadProfileResponse {
|
||||
|
|
@ -34,5 +35,6 @@ export interface LoadProfileResponse {
|
|||
tickets: Tickets;
|
||||
stamps: Set<StampCode>;
|
||||
selectedStamps: SelectedStamps;
|
||||
weeklyMissions: WeeklyMissions;
|
||||
// giga TODO
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import { SqlTicketsRepository } from "./tickets";
|
|||
import { SqlTimeAttackRepository } from "./timeAttack";
|
||||
import { SqlTitlesRepository } from "./titles";
|
||||
import { SqlUnlocksRepository } from "./unlocks";
|
||||
import { SqlWeeklyMissionsRepository } from "./weeklyMissions";
|
||||
import * as Model from "../model";
|
||||
import * as Repo from "../repo";
|
||||
import { Transaction } from "../../../sql";
|
||||
|
|
@ -89,4 +90,8 @@ export class SqlRepositories implements Repo.Repositories {
|
|||
unlocks(): Repo.FacetRepository<Model.Unlocks> {
|
||||
return new SqlUnlocksRepository(this._txn);
|
||||
}
|
||||
|
||||
weeklyMissions(): Repo.WeeklyMissionsRepository {
|
||||
return new SqlWeeklyMissionsRepository(this._txn);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
72
src/idz/userdb/sql/weeklyMissions.ts
Normal file
72
src/idz/userdb/sql/weeklyMissions.ts
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
import sql from "sql-bricks-postgres";
|
||||
|
||||
import { WeeklyMissions } from "../model/weeklyMissions";
|
||||
import { Profile } from "../model/profile";
|
||||
import { WeeklyMissionsRepository } from "../repo";
|
||||
import { Id } from "../../../model";
|
||||
import { Transaction } from "../../../sql";
|
||||
|
||||
const defaultWeeklyMissions: WeeklyMissions = {
|
||||
weeklyReset: new Date(),
|
||||
weeklyMissionLeft: 0,
|
||||
weeklyProgressLeft: 0,
|
||||
weeklyParamsLeft: 0,
|
||||
weeklyMissionRight: 0,
|
||||
weeklyProgressRight: 0,
|
||||
weeklyParamsRight: 0,
|
||||
};
|
||||
|
||||
export class SqlWeeklyMissionsRepository implements WeeklyMissionsRepository {
|
||||
constructor(private readonly _txn: Transaction) {}
|
||||
|
||||
async load(profileId: Id<Profile>): Promise<WeeklyMissions> {
|
||||
const loadSql = sql
|
||||
.select("wm.*")
|
||||
.from("idz_weekly_missions wm")
|
||||
.where("wm.id", profileId);
|
||||
|
||||
const row = await this._txn.fetchRow(loadSql);
|
||||
|
||||
if (row === undefined) {
|
||||
return { ...defaultWeeklyMissions };
|
||||
}
|
||||
|
||||
return {
|
||||
weeklyReset: new Date(row.weekly_reset!),
|
||||
weeklyMissionLeft: parseInt(row.mission_left!),
|
||||
weeklyProgressLeft: parseInt(row.progress_left!),
|
||||
weeklyParamsLeft: parseInt(row.params_left!),
|
||||
weeklyMissionRight: parseInt(row.mission_right!),
|
||||
weeklyProgressRight: parseInt(row.progress_right!),
|
||||
weeklyParamsRight: parseInt(row.params_right!),
|
||||
};
|
||||
}
|
||||
|
||||
async save(
|
||||
profileId: Id<Profile>,
|
||||
weeklyMissions: WeeklyMissions
|
||||
): Promise<void> {
|
||||
const saveSql = sql
|
||||
.insert("idz_weekly_missions", {
|
||||
id: profileId,
|
||||
weekly_reset: weeklyMissions.weeklyReset,
|
||||
mission_left: weeklyMissions.weeklyMissionLeft,
|
||||
progress_left: weeklyMissions.weeklyProgressLeft,
|
||||
params_left: weeklyMissions.weeklyParamsLeft,
|
||||
mission_right: weeklyMissions.weeklyMissionRight,
|
||||
progress_right: weeklyMissions.weeklyProgressRight,
|
||||
params_right: weeklyMissions.weeklyParamsRight,
|
||||
})
|
||||
.onConflict("profile_id")
|
||||
.doUpdate([
|
||||
"weekly_reset",
|
||||
"mission_left",
|
||||
"progress_left",
|
||||
"params_left",
|
||||
"mission_right",
|
||||
"progress_right",
|
||||
"params_right",
|
||||
]);
|
||||
await this._txn.modify(saveSql);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user