Adding a ton of stuff

This commit is contained in:
2026-07-17 04:39:18 -07:00
parent 8d9fe8e75d
commit de28a67417
63 changed files with 2027 additions and 613 deletions
@@ -0,0 +1,49 @@
import { isNil } from "lodash"
import logger from "@/utils/logger"
import { User } from "@/models"
import { UpsertService } from "@/services/users/preferences"
import { UsersPolicy } from "@/policies/users-policy"
import BaseController from "@/controllers/base-controller"
export class PreferencesController extends BaseController {
async update() {
try {
const user = await this.loadUser()
if (isNil(user)) {
return this.response.status(404).json({
message: "User not found",
})
}
const policy = this.buildPolicy(user)
if (!policy.update()) {
return this.response.status(403).json({
message: "You are not authorized to update this user",
})
}
const key = this.request.params.key as string
const { value } = this.request.body
await UpsertService.perform(user, key, value)
return this.response.json({ message: "Successfully upserted user preference" })
} catch (error) {
logger.error(error)
return this.response.status(422).json({
message: `Error updating user: ${error}`,
})
}
}
private async loadUser(): Promise<User | null> {
return User.findByPk(this.params.UserId)
}
private buildPolicy(User: User) {
return new UsersPolicy(this.currentUser, User)
}
}
export default PreferencesController