mirror of
https://github.com/djhackersdev/minime.git
synced 2026-07-07 20:44:06 -05:00
idz: Tweak ProfileRepository interface
This commit is contained in:
parent
9c06d6635f
commit
85510ee0e1
|
|
@ -1,23 +1,22 @@
|
|||
import * as sql from "sql-bricks";
|
||||
import { ClientBase } from "pg";
|
||||
|
||||
import { ExtId } from "../model/base";
|
||||
import { Profile } from "../model/profile";
|
||||
import { Team } from "../model/team";
|
||||
import { ProfileSpec, ProfileRepository } from "../repo";
|
||||
import { ProfileRepository } from "../repo";
|
||||
import { generateId, Id } from "../../db";
|
||||
import { AimeId } from "../../model";
|
||||
|
||||
function _extractProfile(row: any): Profile {
|
||||
return {
|
||||
aimeId: row.ext_id,
|
||||
teamId: 2 as ExtId<Team>, // TODO
|
||||
aimeId: row.aime_id,
|
||||
name: row.name,
|
||||
lv: row.lv,
|
||||
exp: row.exp,
|
||||
fame: row.fame,
|
||||
dpoint: row.dpoint,
|
||||
mileage: row.mileage,
|
||||
accessTime: row.access_time,
|
||||
registerTime: row.register_time,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -54,9 +53,10 @@ export class SqlProfileRepository implements ProfileRepository {
|
|||
|
||||
async load(id: Id<Profile>): Promise<Profile> {
|
||||
const loadSql = sql
|
||||
.select("p.*")
|
||||
.select("p.*", "r.ext_id as aime_id")
|
||||
.from("idz.profile p")
|
||||
.where("id", id)
|
||||
.join("aime.player r", { "p.player_id": "r.id" })
|
||||
.where("p.id", id)
|
||||
.toParams();
|
||||
|
||||
const { rows } = await this._conn.query(loadSql);
|
||||
|
|
@ -64,7 +64,7 @@ export class SqlProfileRepository implements ProfileRepository {
|
|||
return _extractProfile(rows[0]);
|
||||
}
|
||||
|
||||
async save(profile: Profile, timestamp: Date): Promise<void> {
|
||||
async save(id: Id<Profile>, profile: Profile): Promise<void> {
|
||||
const saveSql = sql
|
||||
.update("idz.profile", {
|
||||
lv: profile.lv,
|
||||
|
|
@ -72,23 +72,19 @@ export class SqlProfileRepository implements ProfileRepository {
|
|||
fame: profile.fame,
|
||||
dpoint: profile.dpoint,
|
||||
mileage: profile.mileage,
|
||||
access_time: timestamp,
|
||||
access_time: profile.accessTime,
|
||||
})
|
||||
.where("id", profile.aimeId)
|
||||
.where("id", id)
|
||||
.toParams();
|
||||
|
||||
await this._conn.query(saveSql);
|
||||
}
|
||||
|
||||
async create(
|
||||
aimeId: AimeId,
|
||||
profile: ProfileSpec,
|
||||
timestamp: Date
|
||||
): Promise<Id<Profile>> {
|
||||
async create(profile: Profile): Promise<Id<Profile>> {
|
||||
const findSql = sql
|
||||
.select("r.id")
|
||||
.from("aime.player r")
|
||||
.where("r.ext_id", aimeId)
|
||||
.where("r.ext_id", profile.aimeId)
|
||||
.toParams();
|
||||
|
||||
const { rows } = await this._conn.query(findSql);
|
||||
|
|
@ -111,8 +107,8 @@ export class SqlProfileRepository implements ProfileRepository {
|
|||
fame: profile.fame,
|
||||
dpoint: profile.dpoint,
|
||||
mileage: profile.mileage,
|
||||
register_time: timestamp,
|
||||
access_time: timestamp,
|
||||
register_time: profile.registerTime,
|
||||
access_time: profile.accessTime,
|
||||
})
|
||||
.toParams();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,26 +1,29 @@
|
|||
import { ExtId } from "../model/base";
|
||||
import { MissionState } from "../model/mission";
|
||||
import { Profile } from "../model/profile";
|
||||
import { Settings } from "../model/settings";
|
||||
import { Story } from "../model/story";
|
||||
import { Team } from "../model/team";
|
||||
import { Unlocks } from "../model/unlocks";
|
||||
import { CreateProfileRequest } from "../request/createProfile";
|
||||
import { GenericResponse } from "../response/generic";
|
||||
import { ProfileSpec, Repositories } from "../repo";
|
||||
import { Repositories } from "../repo";
|
||||
|
||||
export async function createProfile(
|
||||
w: Repositories,
|
||||
req: CreateProfileRequest
|
||||
): Promise<GenericResponse> {
|
||||
const { aimeId, name } = req;
|
||||
const now = new Date();
|
||||
const profile: ProfileSpec = {
|
||||
teamId: 2 as ExtId<Team>, // TODO
|
||||
name: req.name,
|
||||
|
||||
const profile: Profile = {
|
||||
aimeId,
|
||||
name,
|
||||
lv: 1,
|
||||
exp: 0,
|
||||
fame: 0,
|
||||
dpoint: 0,
|
||||
mileage: 0,
|
||||
accessTime: now,
|
||||
registerTime: now,
|
||||
};
|
||||
|
||||
const missions: MissionState = { team: [], solo: [] };
|
||||
|
|
@ -33,7 +36,7 @@ export async function createProfile(
|
|||
lastMileageReward: 0,
|
||||
};
|
||||
|
||||
const profileId = await w.profile().create(req.aimeId, profile, now);
|
||||
const profileId = await w.profile().create(profile);
|
||||
|
||||
await w.chara().save(profileId, req.chara);
|
||||
await w.car().saveCar(profileId, req.car);
|
||||
|
|
@ -46,6 +49,6 @@ export async function createProfile(
|
|||
|
||||
return {
|
||||
type: "generic_res",
|
||||
status: req.aimeId, // "Generic response" my fucking *ass*
|
||||
status: aimeId, // "Generic response" my fucking *ass*
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ export async function discoverProfile(
|
|||
w: Repositories,
|
||||
req: DiscoverProfileRequest
|
||||
): Promise<DiscoverProfileResponse> {
|
||||
const profileId = await w.profile().find(req.aimeId);
|
||||
const profileId = await w.profile().peek(req.aimeId);
|
||||
|
||||
return {
|
||||
type: "discover_profile_res",
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ export async function loadProfile(
|
|||
fame: profile.fame,
|
||||
dpoint: profile.dpoint,
|
||||
mileage: profile.mileage,
|
||||
teamId: profile.teamId,
|
||||
// teamId: TODO
|
||||
settings,
|
||||
chara,
|
||||
titles,
|
||||
|
|
|
|||
|
|
@ -11,17 +11,15 @@ export async function saveProfile(
|
|||
const profile = await w.profile().load(profileId);
|
||||
const chara = await w.chara().load(profileId);
|
||||
|
||||
await w.profile().save(
|
||||
{
|
||||
...profile,
|
||||
lv: req.lv,
|
||||
exp: req.exp,
|
||||
fame: req.fame,
|
||||
dpoint: req.dpoint,
|
||||
mileage: req.mileage,
|
||||
},
|
||||
now
|
||||
);
|
||||
await w.profile().save(profileId, {
|
||||
...profile,
|
||||
lv: req.lv,
|
||||
exp: req.exp,
|
||||
fame: req.fame,
|
||||
dpoint: req.dpoint,
|
||||
mileage: req.mileage,
|
||||
accessTime: now,
|
||||
});
|
||||
|
||||
await w.chara().save(profileId, {
|
||||
...chara,
|
||||
|
|
|
|||
|
|
@ -1,14 +1,13 @@
|
|||
import { ExtId } from "./base";
|
||||
import { Team } from "./team";
|
||||
import { AimeId } from "../../model";
|
||||
|
||||
export interface Profile {
|
||||
aimeId: AimeId;
|
||||
teamId?: ExtId<Team>;
|
||||
name: string;
|
||||
lv: number;
|
||||
exp: number;
|
||||
fame: number;
|
||||
dpoint: number;
|
||||
mileage: number;
|
||||
accessTime: Date;
|
||||
registerTime: Date;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,7 @@
|
|||
import { Subtract } from "utility-types";
|
||||
|
||||
import * as Model from "./model";
|
||||
import { AimeId } from "../model";
|
||||
import { Id } from "../db";
|
||||
|
||||
export type ProfileSpec = Subtract<Model.Profile, { aimeId: AimeId }>;
|
||||
|
||||
export interface CarRepository {
|
||||
countCars(profileId: Id<Model.Profile>): Promise<number>;
|
||||
|
||||
|
|
@ -49,13 +45,9 @@ export interface ProfileRepository {
|
|||
|
||||
load(id: Id<Model.Profile>): Promise<Model.Profile>;
|
||||
|
||||
save(profile: Model.Profile, timestamp: Date): Promise<void>;
|
||||
save(id: Id<Model.Profile>, profile: Model.Profile): Promise<void>;
|
||||
|
||||
create(
|
||||
aimeId: AimeId,
|
||||
profile: ProfileSpec,
|
||||
timestamp: Date
|
||||
): Promise<Id<Model.Profile>>;
|
||||
create(profile: Model.Profile): Promise<Id<Model.Profile>>;
|
||||
}
|
||||
|
||||
// TODO extend and factorize
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user