Skip to content

Commit

Permalink
chore: migrating models and db stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
WorthyD committed Apr 28, 2024
1 parent 58aa55b commit 260a596
Show file tree
Hide file tree
Showing 126 changed files with 454 additions and 224 deletions.
2 changes: 1 addition & 1 deletion apps/destiny-clan-dashboard/src/app/app.providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { ProfileWorkerService } from './workers/profile-worker/profile-worker.se
import { ProfileRecentActivityWorkerService as ProfileRecentActivityWorkerServiceFake } from '@dcd/shared/data-access/member-activity';
import { ProfileRecentActivityWorkerService } from './workers/profile-recent-activity/profile-recent-activity.service';
import { LocationToken, WindowToken, locationProvider, windowProvider } from '@dcd/shared/tokens';
import { IdbKeyValService } from '@destiny-clan-dashboard/data/storage';
import { IdbKeyValService } from '@dcd/shared/utils/storage';
import { ClanMembersService } from '@destiny-clan-dashboard/data/clan/clan-members';
import { ApiKeyInterceptor } from '@dcd/shared/utils/api-key-interceptor';
import { ClanDatabase } from '@destiny-clan-dashboard/data/clan/clan-database';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BehaviorSubject, delay, of, take, tap } from 'rxjs';
import { MemberProfile } from '@destiny-clan-dashboard/data/models';
import { MemberProfile } from '@dcd/shared/models';

export class ProfileWorkerServiceMock {
constructor() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';
//import { MemberProfile, ClanMember } from 'bungie-models';
import { BehaviorSubject, Observable, of, Subject } from 'rxjs';
import { environment } from '../../../environments/environment';
import { MemberProfile } from '@destiny-clan-dashboard/data/models';
import { MemberProfile } from '@dcd/shared/models';
import { SeasonService } from '@dcd/shared/data-access/definitions';

@Injectable()
Expand Down
10 changes: 5 additions & 5 deletions libs/data/src/lib/clan/base-clan.service.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { ClanDatabase } from './clan-database';
import { DBObject, StoreId } from '../db/clan-indexed-db';
import { ClanDbObject, ClanStoreId } from '@dcd/shared/utils/legacy-db';
import { isValidDate, nowPlusMinutes } from '@destiny-clan-dashboard/shared/utils';

export class BaseClanService {
tableName;
constructor(private clanDbBase: ClanDatabase, private tableNameBase: StoreId) {
constructor(private clanDbBase: ClanDatabase, private tableNameBase: ClanStoreId) {
this.tableName = tableNameBase;
}

getDataFromCache(clanId: string, rowId: string): Promise<DBObject> {
getDataFromCache(clanId: string, rowId: string): Promise<ClanDbObject> {
return this.clanDbBase.getById(clanId, this.tableNameBase, rowId);
}

getAllDataFromCache(clanId: string): Promise<DBObject[]> {
getAllDataFromCache(clanId: string): Promise<ClanDbObject[]> {
return this.clanDbBase.getAll(clanId, this.tableNameBase);
}

isCacheValid(cachedData: DBObject, minuteExpiration: number, lastActivity?: Date) {
isCacheValid(cachedData: ClanDbObject, minuteExpiration: number, lastActivity?: Date) {
if (cachedData && cachedData.createDate) {
const cacheDate = cachedData.createDate;
let expireDate;
Expand Down
16 changes: 8 additions & 8 deletions libs/data/src/lib/clan/base-member-activity.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import { groupActivitiesByDate } from '@destiny-clan-dashboard/shared/utils';
import { mergeMap, map, catchError, toArray, switchMap, tap } from 'rxjs/operators';
import { Observable, of, from, defer, concat, EMPTY, forkJoin } from 'rxjs';
import { ClanDatabase } from './clan-database';
import { DBObject, StoreId } from '../db/clan-indexed-db';
import { MemberActivityStats } from '../models/MemberActivityStat';
import { MemberActivityTime } from '../models/MemberActivityTime';
import { ClanDbObject, ClanStoreId } from '@dcd/shared/utils/legacy-db';
import { MemberActivityStats } from '@dcd/shared/models';
import { MemberActivityTime } from '@dcd/shared/models';
import { clanMemberActivitySerializer } from './clan-member-activity/clan-member-activity.serializer';
//import { MemberProfile } from '../models';
//import { clanMemberActivitySerializer } from './clan-member-activity/clan-member-activity.serializer';
Expand All @@ -29,7 +29,7 @@ export class BaseMemberActivityService extends BaseClanService {
private ACTIVITY_GET_COUNT = 250;
constructor(
private clanDbPBase: ClanDatabase,
private tableNamePBase: StoreId,
private tableNamePBase: ClanStoreId,
private apiKey: string,
// private d2ServiceBase: Destiny2Service,
public startValue: Date,
Expand Down Expand Up @@ -154,7 +154,7 @@ export class BaseMemberActivityService extends BaseClanService {
* Determines if Cached data is fresh enough to use. Triggers new call if too old.
*
*/
verifyCacheIntegrity(clanId, memberProfile: MemberProfile, characterId, cachedData: DBObject) {
verifyCacheIntegrity(clanId, memberProfile: MemberProfile, characterId, cachedData: ClanDbObject) {
const characterActivityId = this.getMemberActivityId(memberProfile, characterId);
if (this.isCacheValid(cachedData, 720, new Date(memberProfile.profile.data.dateLastPlayed))) {
return of(cachedData.data);
Expand All @@ -171,7 +171,7 @@ export class BaseMemberActivityService extends BaseClanService {
member: MemberProfile,
characterId: number,
characterActivityId: string,
cachedData: DBObject
cachedData: ClanDbObject
//): Observable<Array<DestinyHistoricalStatsDestinyHistoricalStatsPeriodGroup>> {
): Observable<Array<any>> {
return this.getAllRecentActivity(member, characterId).pipe(
Expand Down Expand Up @@ -203,7 +203,7 @@ export class BaseMemberActivityService extends BaseClanService {

groupActivitiesToMember(
memberProfile: MemberProfile,
allActivities: DBObject[],
allActivities: ClanDbObject[],
activityMode: number = 0,
activityTypeId: number = 0
) {
Expand Down Expand Up @@ -242,7 +242,7 @@ export class BaseMemberActivityService extends BaseClanService {

groupActivitiesToMembers(
memberProfiles: MemberProfile[],
allActivities: DBObject[],
allActivities: ClanDbObject[],
activityMode: number = 0,
activityTypeId = 0
): any[] {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { ClanBungieInfoService } from './bungie-info.service';

import { ClanDatabase } from '../clan-database';
import { DBObject } from '../../db/clan-indexed-db';
import { ClanDbObject } from '@dcd/shared/utils/legacy-db';

import { BungieInfo } from '../../models/BungieInfo';
import { ClanMember } from '../../models';
jest.mock('../clan-database');
const mockedDatabase = ClanDatabase as jest.Mock<ClanDatabase>;
const getMockClanObject: (id?: string, createDate?: Date, data?: BungieInfo) => Partial<DBObject> = (
const getMockClanObject: (id?: string, createDate?: Date, data?: BungieInfo) => Partial<ClanDbObject> = (
id = '',
createDate = new Date(),
data = {}
Expand Down
9 changes: 5 additions & 4 deletions libs/data/src/lib/clan/bungie-info/bungie-info.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import { map, catchError, mergeMap, bufferTime, toArray } from 'rxjs/operators';
import { Observable, from, of, throwError } from 'rxjs';
// import { profileSerializer } from './profile.serializer';
import { isValidDate, nowPlusDays, unixTimeStampToDate } from '@destiny-clan-dashboard/shared/utils';
import { StoreId } from '../../db/clan-indexed-db';
import { ClanStoreId } from '@dcd/shared/utils/legacy-db';
import { ClanDatabase } from '../clan-database';
import { ClanMember } from '../../models/ClanMember';
import { BungieInfo } from '../../models/BungieInfo';
import { ClanMember } from '@dcd/shared/models';
import { BungieInfo } from '@dcd/shared/models';
//import { BungieInfo } from '../../models/BungieInfo';
interface MemberProfile {}

export class ClanBungieInfoService {
private tableName: StoreId = StoreId.BungieInfo;
private tableName: ClanStoreId = ClanStoreId.BungieInfo;
private concurrentRequests = 20;
private CACHE_EXPIRATION = -1;

Expand Down
18 changes: 9 additions & 9 deletions libs/data/src/lib/clan/clan-database.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
// import { Injectable } from '@angular/core';
import { AppIndexedDb, StoreId, DBObject, STORE_IDS } from '../db/clan-indexed-db';
import { ClanIndexedDb, ClanStoreId, ClanDbObject, CLAN_STORE_IDS } from '@dcd/shared/utils/legacy-db'

// @Injectable({providedIn: 'root'})
export class ClanDatabase {
private databases: { [key: string]: AppIndexedDb };
private databases: { [key: string]: ClanIndexedDb };
// private database: AppIndexedDb;
constructor() {
this.databases = {};
}

getAll(repository: string, type: StoreId): Promise<DBObject[]> {
getAll(repository: string, type: ClanStoreId): Promise<ClanDbObject[]> {
return this.getDatabase(repository).getAllData(type);
}

getById(repository: string, type: StoreId, id: string): Promise<DBObject> {
getById(repository: string, type: ClanStoreId, id: string): Promise<ClanDbObject> {
return this.getDatabase(repository).getById(type, id);
}

update(repository: string, type: StoreId, entities: any[]): Promise<void> {
update(repository: string, type: ClanStoreId, entities: any[]): Promise<void> {
return this.getDatabase(repository).updateValues(entities, type);
}

remove(repository: string, type: StoreId, ids: string[]): Promise<void> {
remove(repository: string, type: ClanStoreId, ids: string[]): Promise<void> {
return this.getDatabase(repository).removeValues(ids, type);
}

removeAll(repository: string, type: StoreId) {
removeAll(repository: string, type: ClanStoreId) {
return this.getDatabase(repository).removeAllValues(type);
}

Expand All @@ -34,7 +34,7 @@ export class ClanDatabase {
}

purgeDatabase(repository: string) {
STORE_IDS.forEach((storeId) => {
CLAN_STORE_IDS.forEach((storeId) => {
this.getDatabase(repository, false).removeAllValues(storeId);
});
}
Expand All @@ -43,7 +43,7 @@ export class ClanDatabase {
if (this.databases && this.databases[repository]) {
return this.databases[repository];
}
const newDB = new AppIndexedDb(repository, initializeValues);
const newDB = new ClanIndexedDb(repository, initializeValues);
this.databases[repository] = newDB;
return this.databases[repository];
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GroupsV2GroupV2, GroupsV2GroupV2ClanInfoAndInvestment } from 'bungie-api-angular';
import { ClanDetails } from '../../models/ClanDetails';
import { ClanDetails } from '@dcd/shared/models';

export function clanDetailSerializer(group: GroupsV2GroupV2, progressionHashes: string[]): ClanDetails {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { GroupV2Service } from 'bungie-api-angular';
import { ClanDatabase } from '../clan-database';
import { ClanDetailsService } from './clan-details.service';
import { DBObject } from '../../db/clan-indexed-db';
import { ClanDetails } from '../../models/ClanDetails';
import { ClanDetails } from '@dcd/shared/models';
import { getMockClan } from '../../models/__mocks__/clan-details';
import { defer, of } from 'rxjs';

Expand Down
4 changes: 2 additions & 2 deletions libs/data/src/lib/clan/clan-details/clan-details.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { map, take, catchError, mergeMap, switchMap } from 'rxjs/operators';
import { ClanDatabase } from '../clan-database';
import { of, from } from 'rxjs';
import { BaseClanService } from '../base-clan.service';
import { StoreId } from '../../db/clan-indexed-db';
import { ClanStoreId } from '@dcd/shared/utils/legacy-db';
import { clanDetailSerializer } from './clan-detail-serializer';
import { CLAN_LEVEL_HASH } from '../../hashes/clan-details';

Expand All @@ -15,7 +15,7 @@ export class ClanDetailsService extends BaseClanService {
private rowId = 'ClanDetails';

constructor(private groupService: GroupV2Service, private clanDb: ClanDatabase) {
super(clanDb, StoreId.ClanDetails);
super(clanDb, ClanStoreId.ClanDetails);
}
private getClanDetailsFromAPI(clanId: string) {
return this.groupService.groupV2GetGroup(clanId as unknown as number);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// import { DestinyHistoricalStatsDestinyHistoricalStatsPeriodGroup } from 'bungie-api-angular';

import { DestinyHistoricalStatsDestinyHistoricalStatsPeriodGroup } from '../../models/DestinyHistoricalStatsDestinyHistoricalStatsPeriodGroup';

import { DestinyHistoricalStatsDestinyHistoricalStatsPeriodGroup } from '@dcd/shared/models';
// import { DestinyHistoricalStatsDestinyHistoricalStatsPeriodGroup } from 'bungie-api-angular/lib/model/destinyHistoricalStatsDestinyHistoricalStatsPeriodGroup';

export function clanMemberActivitySerializer(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// import { MemberActivityStats, MemberActivityRecentStats, MemberActivityRecentStatsActivity } from 'bungie-models';
import { MemberActivityRecentStats, MemberActivityRecentStatsActivity } from '../../models/MemberActivityRecentStats';
import { MemberActivityStats } from '../../models/MemberActivityStat';
import { MemberActivityRecentStats, MemberActivityRecentStatsActivity } from'@dcd/shared/models';
import { MemberActivityStats } from '@dcd/shared/models';
// import { MemberActivityRecentStats } from 'projects/components/src/lib/clan-roster-activity-table/clan-roster-activity-table.component';
import { groupActivities } from '@destiny-clan-dashboard/shared/utils';
//import { getBungieStartDate } from '../../utility/date-utils';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import { mergeMap, map, toArray } from 'rxjs/operators';
//import { MemberProfile } from 'projects/bungie-models/src/lib/models/MemberProfile';
//import { MemberActivityRecentStats } from 'projects/bungie-models/src/lib/models/MemberActivityRecentStats';
import { ClanDatabase } from '../clan-database';
import { StoreId } from '../../db/clan-indexed-db';
import { ClanStoreId } from '@dcd/shared/utils/legacy-db';
// import { MemberProfile } from '../../models';
import { MemberActivityRecentStats } from '../../models/MemberActivityRecentStats';
import { MemberActivityRecentStats } from '@dcd/shared/models';
import { clanMemberRecentActivitySerializer, TrackedDuration } from './clan-member-recent-activity.serializer';

interface MemberProfile {
Expand All @@ -23,7 +23,7 @@ export class ClanMemberRecentActivityService extends BaseMemberActivityService {
constructor(private clanDB: ClanDatabase, private baseApiKey: string) {
super(
clanDB,
StoreId.MemberRecentActivities,
ClanStoreId.MemberRecentActivities,
baseApiKey,
new Date(new Date().setDate(new Date().getDate() + ((2 + 7 - new Date().getDay()) % 7) - 90)),
8,
Expand Down
8 changes: 4 additions & 4 deletions libs/data/src/lib/clan/clan-members/clan-members.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Destiny2Service, GroupsV2GroupMember, GroupV2Service } from 'bungie-api
//import { DBObject, StoreId } from '../app-indexed-db';

import { map, take, catchError, mergeMap, switchMap, shareReplay, concatMap } from 'rxjs/operators';
import { StoreId } from '../../db/clan-indexed-db';
import { ClanStoreId } from '@dcd/shared/utils/legacy-db';
import { ClanDatabase } from '../clan-database';
import { of, from, Observable } from 'rxjs';
import { BaseClanService } from '../base-clan.service';
Expand All @@ -13,7 +13,7 @@ import { ClanMembersServiceInterface } from './clan-members.interface';
export class ClanMembersService extends BaseClanService implements ClanMembersServiceInterface {
private rowId = 'ClanMembers';
constructor(private groupService: GroupV2Service, private clanDb: ClanDatabase) {
super(clanDb, StoreId.ClanDetails);
super(clanDb, ClanStoreId.ClanDetails);
}

private getClanMembersFromAPI(clanId: string) {
Expand Down Expand Up @@ -58,11 +58,11 @@ export class ClanMembersService extends BaseClanService implements ClanMembersSe
);
}
getClanMembersCachedSerialized(clanId: string): Observable<GroupsV2GroupMember[]> {
// console.log(`getting-${clanId}`);
// console.log(`getting-${clanId}`);
return from(this.getDataFromCache(clanId, this.rowId))
.pipe(
map((x) => {
// console.log(`getting-done-${clanId}`);
// console.log(`getting-done-${clanId}`);
return x?.data;
})
)
Expand Down
6 changes: 3 additions & 3 deletions libs/data/src/lib/clan/profiles/profile.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { Observable, from, of } from 'rxjs';
//import { StoreId } from '../app-indexed-db';

import { nowPlusDays, unixTimeStampToDate } from '@destiny-clan-dashboard/shared/utils';
import { StoreId } from '../../db/clan-indexed-db';
import { ClanStoreId } from '@dcd/shared/utils/legacy-db';
import { ClanDatabase } from '../clan-database';
import { ClanMember } from '../../models/ClanMember';
import { ClanMember } from '@dcd/shared/models';
import { ProfileService } from '../../profile/profile.service';
import { profileSerializer } from '../../profile/profile.serializer';
//import { MemberProfile } from '../../models/MemberProfile';
Expand All @@ -16,7 +16,7 @@ import { profileSerializer } from '../../profile/profile.serializer';
interface MemberProfile {}

export class ClanProfileService extends ProfileService {
private tableName: StoreId = StoreId.MemberProfiles;
private tableName: ClanStoreId = ClanStoreId.MemberProfiles;
private concurrentRequests = 20;

// private profileComponents = [100, 104, 200, 202, 800, 900, 1100];
Expand Down
2 changes: 1 addition & 1 deletion libs/data/src/lib/manifest/manifest-loader.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Inject, Injectable } from '@angular/core';
import { Destiny2Service } from 'bungie-api-angular';
import { map, Observable, of, switchMap, take } from 'rxjs';
import { WindowToken } from '@dcd/shared/tokens';
import { IdbKeyValService } from '../storage/idb-key-val.service';
import { IdbKeyValService } from '@dcd/shared/utils/storage';
import { nowPlusMinutes } from '@destiny-clan-dashboard/shared/utils';

export const STATUS_EXTRACTING_TABLES = 'extracting tables';
Expand Down
3 changes: 0 additions & 3 deletions libs/data/src/lib/models/Character.ts

This file was deleted.

6 changes: 0 additions & 6 deletions libs/data/src/lib/models/ClanMemberSeasonPass.ts

This file was deleted.

3 changes: 0 additions & 3 deletions libs/data/src/lib/models/CollectionDefinition.ts

This file was deleted.

12 changes: 0 additions & 12 deletions libs/data/src/lib/models/MemberActivityRecentStats.ts

This file was deleted.

Loading

0 comments on commit 260a596

Please sign in to comment.