Merge remote-tracking branch 'origin/main' into feature/#182-reset-password
# Conflicts: # src/utilities/http.ts
This commit is contained in:
@ -33,6 +33,7 @@ class UserService {
|
||||
/**
|
||||
* Register user
|
||||
* @param username
|
||||
* @param email
|
||||
* @param password
|
||||
*/
|
||||
async register(username: string, email: string, password: string): Promise<boolean | User> {
|
||||
|
@ -1,4 +1,14 @@
|
||||
import prisma from '../utilities/prisma'
|
||||
import { AssetData } from '../utilities/types'
|
||||
import tileRepository from '../repositories/tileRepository'
|
||||
import zoneRepository from '../repositories/zoneRepository'
|
||||
import { Object, Zone, ZoneObject } from '@prisma/client'
|
||||
|
||||
type getZoneAsetsZoneType = Zone & {
|
||||
zoneObjects: (ZoneObject & {
|
||||
object: Object
|
||||
})[]
|
||||
}
|
||||
|
||||
class ZoneService {
|
||||
async createDemoZone(): Promise<boolean> {
|
||||
@ -27,6 +37,49 @@ class ZoneService {
|
||||
console.log('Demo zone created.')
|
||||
return true
|
||||
}
|
||||
|
||||
async getZoneAssets(zone: getZoneAsetsZoneType): Promise<AssetData[]> {
|
||||
const assets: AssetData[] = []
|
||||
|
||||
// zone.tiles is prisma jsonvalue
|
||||
let tiles = JSON.parse(JSON.stringify(zone.tiles))
|
||||
tiles = [...new Set(tiles.flat())]
|
||||
|
||||
// Add tile assets
|
||||
for (const tile of tiles) {
|
||||
const tileInfo = await tileRepository.getById(tile)
|
||||
if (!tileInfo) continue
|
||||
|
||||
assets.push({
|
||||
key: tileInfo.id,
|
||||
data: '/assets/tiles/' + tileInfo.id + '.png',
|
||||
group: 'tiles',
|
||||
updatedAt: tileInfo?.updatedAt || new Date()
|
||||
} as AssetData)
|
||||
}
|
||||
|
||||
// Add object assets
|
||||
for (const zoneObject of zone.zoneObjects) {
|
||||
if (!zoneObject.object) continue
|
||||
|
||||
assets.push({
|
||||
key: zoneObject.object.id,
|
||||
data: '/assets/objects/' + zoneObject.object.id + '.png',
|
||||
group: 'objects',
|
||||
updatedAt: zoneObject.object.updatedAt || new Date()
|
||||
} as AssetData)
|
||||
}
|
||||
|
||||
// Filter out duplicate assets
|
||||
return assets.reduce((acc: AssetData[], current) => {
|
||||
const x = acc.find((item) => item.key === current.key && item.group === current.group)
|
||||
if (!x) {
|
||||
return acc.concat([current])
|
||||
} else {
|
||||
return acc
|
||||
}
|
||||
}, [])
|
||||
}
|
||||
}
|
||||
|
||||
export default ZoneService
|
||||
|
Reference in New Issue
Block a user