feat: set map creator details on pin setting

This commit is contained in:
Ben Furber
2024-09-05 17:02:15 +01:00
committed by benfurber
parent 590f9e3dcc
commit fe3114d83b

View File

@@ -1,6 +1,7 @@
import { action, makeObservable, observable } from 'mobx' import { action, makeObservable, observable } from 'mobx'
import { IModerationStatus, ProfileTypeList } from 'oa-shared' import { IModerationStatus, ProfileTypeList } from 'oa-shared'
import { logger } from 'src/logger' import { logger } from 'src/logger'
import { DEFAULT_PUBLIC_CONTACT_PREFERENCE } from 'src/pages/UserSettings/constants'
import { import {
hasAdminRights, hasAdminRights,
isAllowedToPin, isAllowedToPin,
@@ -20,7 +21,7 @@ import type {
IMapPin, IMapPin,
IMapPinWithDetail, IMapPinWithDetail,
} from 'src/models/maps.models' } from 'src/models/maps.models'
import type { IUserPP } from 'src/models/userPreciousPlastic.models' import type { IUserPP, IUserPPDB } from 'src/models/userPreciousPlastic.models'
import type { IRootStore } from '../RootStore' import type { IRootStore } from '../RootStore'
import type { IUploadedFileMeta } from '../storage' import type { IUploadedFileMeta } from '../storage'
@@ -166,9 +167,23 @@ export class MapsStore extends ModuleStore {
) )
} }
public async setUserPin(user: IUserPP) { public async setUserPin(user: IUserPPDB) {
const type = user.profileType || ProfileTypeList.MEMBER const {
const existingPin = await this.getPin(user.userName, 'server') _id,
_lastActive,
about,
badges,
coverImages,
displayName,
location,
profileType,
isContactableByPublic,
verified,
workspaceType,
userImage,
} = user
const type = profileType || ProfileTypeList.MEMBER
const existingPin = await this.getPin(_id, 'server')
const existingModeration = existingPin?.moderation const existingModeration = existingPin?.moderation
const existingPinType = existingPin?.type const existingPinType = existingPin?.type
@@ -190,18 +205,42 @@ export class MapsStore extends ModuleStore {
moderation = IModerationStatus.AWAITING_MODERATION moderation = IModerationStatus.AWAITING_MODERATION
} }
const coverImage =
coverImages && coverImages[0]?.downloadUrl
? { coverImage: coverImages[0].downloadUrl }
: {}
const pin: IMapPin = { const pin: IMapPin = {
_id: user.userName, _id,
_deleted: !user.location?.latlng, _deleted: !user.location?.latlng,
location: user.location!.latlng, location: location!.latlng,
type, type,
...(!isMember && workspaceType ? { subType: workspaceType } : {}),
moderation, moderation,
verified: user.verified, verified,
creator: {
_id,
_lastActive: _lastActive || '',
...(about ? { about } : {}),
...(badges
? {
badges: {
verified: badges.verified || false,
supporter: badges.supporter || false,
},
}
: {}),
countryCode: location?.countryCode || '',
...coverImage,
displayName,
isContactableByPublic:
isContactableByPublic || DEFAULT_PUBLIC_CONTACT_PREFERENCE,
profileType,
...(workspaceType ? { subType: workspaceType } : {}),
...(userImage ? { userImage: userImage.downloadUrl } : {}),
},
} }
if (!isMember && user.workspaceType) {
pin.subType = user.workspaceType
}
logger.debug('setting user pin', pin) logger.debug('setting user pin', pin)
await this.db.collection<IMapPin>(COLLECTION_NAME).doc(pin._id).set(pin) await this.db.collection<IMapPin>(COLLECTION_NAME).doc(pin._id).set(pin)
} }