mirror of
https://github.com/vkaelin/LeagueStats.git
synced 2026-03-25 12:57:28 +00:00
refactor: create Summoner Mongo Model
This commit is contained in:
parent
e35492840e
commit
25af97d4a6
5 changed files with 27 additions and 20 deletions
|
|
@ -1,6 +1,5 @@
|
||||||
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||||
import { SummonerModel } from '@ioc:Adonis/League'
|
import Summoner from 'App/Models/Summoner'
|
||||||
import mongodb from '@ioc:Mongodb/Database'
|
|
||||||
import MatchRepository from 'App/Repositories/MatchRepository'
|
import MatchRepository from 'App/Repositories/MatchRepository'
|
||||||
import Jax from 'App/Services/Jax'
|
import Jax from 'App/Services/Jax'
|
||||||
import MatchService from 'App/Services/MatchService'
|
import MatchService from 'App/Services/MatchService'
|
||||||
|
|
@ -44,11 +43,9 @@ export default class SummonersController {
|
||||||
// { puuid: account.puuid }
|
// { puuid: account.puuid }
|
||||||
// )
|
// )
|
||||||
|
|
||||||
const summonersCollection = await mongodb.connection().collection('summoners')
|
let summonerDB = await Summoner.findOne({ puuid: account.puuid })
|
||||||
let summonerDB:SummonerModel|null = await summonersCollection.findOne({ puuid: account.puuid })
|
|
||||||
if(!summonerDB) {
|
if(!summonerDB) {
|
||||||
await summonersCollection.insertOne({ puuid: account.puuid })
|
summonerDB = await Summoner.create({ puuid: account.puuid })
|
||||||
summonerDB = {puuid: account.puuid }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Summoner names
|
// Summoner names
|
||||||
|
|
@ -71,7 +68,7 @@ export default class SummonersController {
|
||||||
|
|
||||||
// SAVE IN DB
|
// SAVE IN DB
|
||||||
// await summonerDB.save()
|
// await summonerDB.save()
|
||||||
await summonersCollection.updateOne({ puuid: account.puuid }, summonerDB)
|
await summonerDB.save()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('username not found')
|
console.log('username not found')
|
||||||
console.log(error)
|
console.log(error)
|
||||||
|
|
|
||||||
21
server-new/app/Models/Summoner.ts
Normal file
21
server-new/app/Models/Summoner.ts
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
import { Model } from '@ioc:Mongodb/Model'
|
||||||
|
import { MatchReferenceDto } from 'App/Services/Jax/src/Endpoints/MatchlistEndpoint'
|
||||||
|
|
||||||
|
export interface SummonerModel {
|
||||||
|
puuid: string,
|
||||||
|
matchList?: MatchReferenceDto[],
|
||||||
|
names?: SummonerNames[]
|
||||||
|
}
|
||||||
|
|
||||||
|
interface SummonerNames {
|
||||||
|
name: string,
|
||||||
|
date: Date
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class Summoner extends Model implements SummonerModel {
|
||||||
|
public static collectionName = 'summoners'
|
||||||
|
|
||||||
|
public puuid: string
|
||||||
|
public matchList?: MatchReferenceDto[]
|
||||||
|
public names?: SummonerNames[]
|
||||||
|
}
|
||||||
|
|
@ -3,7 +3,7 @@ import Jax from './Jax'
|
||||||
import { getSeasonNumber } from 'App/helpers'
|
import { getSeasonNumber } from 'App/helpers'
|
||||||
import { MatchReferenceDto } from './Jax/src/Endpoints/MatchListEndpoint'
|
import { MatchReferenceDto } from './Jax/src/Endpoints/MatchListEndpoint'
|
||||||
import { SummonerDTO } from './Jax/src/Endpoints/SummonerEndpoint'
|
import { SummonerDTO } from './Jax/src/Endpoints/SummonerEndpoint'
|
||||||
import { SummonerModel } from '@ioc:Adonis/League'
|
import { SummonerModel } from 'App/Models/Summoner'
|
||||||
|
|
||||||
class MatchService {
|
class MatchService {
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import Jax from './Jax'
|
import Jax from './Jax'
|
||||||
import { SummonerDTO } from 'App/Services/Jax/src/Endpoints/SummonerEndpoint'
|
import { SummonerDTO } from 'App/Services/Jax/src/Endpoints/SummonerEndpoint'
|
||||||
import { LeagueEntryDTO } from './Jax/src/Endpoints/LeagueEndpoint'
|
import { LeagueEntryDTO } from './Jax/src/Endpoints/LeagueEndpoint'
|
||||||
import { SummonerModel } from '@ioc:Adonis/League'
|
import { SummonerModel } from 'App/Models/Summoner'
|
||||||
|
|
||||||
class SummonerService {
|
class SummonerService {
|
||||||
private uniqueLeagues = ['CHALLENGER', 'GRANDMASTER', 'MASTER']
|
private uniqueLeagues = ['CHALLENGER', 'GRANDMASTER', 'MASTER']
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,3 @@
|
||||||
declare module '@ioc:Adonis/League' {
|
declare module '@ioc:Adonis/League' {
|
||||||
import { MatchReferenceDto } from 'App/Services/Jax/src/Endpoints/MatchlistEndpoint'
|
|
||||||
|
|
||||||
interface SummonerModel {
|
|
||||||
puuid: string,
|
|
||||||
matchList?: MatchReferenceDto[],
|
|
||||||
names?: SummonerNames[]
|
|
||||||
}
|
|
||||||
|
|
||||||
interface SummonerNames {
|
|
||||||
name: string,
|
|
||||||
date: Date
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue