@xrengine/server-core
Version:
Shared components for XREngine server
32 lines (28 loc) • 892 B
text/typescript
import { HookContext } from '@feathersjs/feathers'
import { UserInterface } from '@xrengine/common/src/interfaces/User'
// This will attach the owner ID in the contact while creating/updating list item
export default (propertyName: string) => {
return (context: HookContext): HookContext => {
// console.log('\n\n\n', context)
// Getting logged in user and attaching owner of user
const loggedInUser = context.params.user as UserInterface
if (Array.isArray(context.data)) {
context.data = context.data.map((item) => {
return {
...item,
[]: loggedInUser.id
}
})
} else {
context.data = {
...context.data,
[]: loggedInUser.id
}
context.params.body = {
...context.params.body,
[]: loggedInUser.id
}
}
return context
}
}