feat: exclude user preferences from payload
This commit is contained in:
parent
23ce4e22e8
commit
25fb5588fa
1 changed files with 22 additions and 0 deletions
|
|
@ -1,8 +1,29 @@
|
|||
import { DateTime } from 'luxon'
|
||||
import { BaseModel, column, computed } from '@adonisjs/lucid/orm'
|
||||
import { DbRememberMeTokensProvider } from '@adonisjs/auth/session'
|
||||
import { HttpContext } from '@adonisjs/core/http'
|
||||
|
||||
export default class User extends BaseModel {
|
||||
serializeExtras = true
|
||||
|
||||
serialize() {
|
||||
const ctx = HttpContext.get()
|
||||
|
||||
if (!ctx || !ctx.request.url().startsWith('/users')) {
|
||||
this.serializeExtras = false
|
||||
const serialized = super.serialize()
|
||||
delete serialized.pastStudentId
|
||||
delete serialized.extras
|
||||
return serialized
|
||||
}
|
||||
|
||||
this.serializeExtras = true
|
||||
return {
|
||||
...super.serialize(),
|
||||
preferences: this.preferences,
|
||||
}
|
||||
}
|
||||
|
||||
static rememberMeTokens = DbRememberMeTokensProvider.forModel(User)
|
||||
|
||||
@column({ isPrimary: true })
|
||||
|
|
@ -33,6 +54,7 @@ export default class User extends BaseModel {
|
|||
|
||||
@computed()
|
||||
get preferences(): { name: string; emoji: string; color: string }[] {
|
||||
if (!this.serializeExtras) return []
|
||||
return this.extras?.preferences || []
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue