mirror of
https://github.com/standardnotes/server
synced 2026-07-14 00:01:54 -04:00
* fix: rename home server controllers to base controllers * fix: rename inversify express controllers to annotated controllers
43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
import { ControllerContainerInterface } from '@standardnotes/domain-core'
|
|
import { Request, Response } from 'express'
|
|
|
|
import { GetUserFeatures } from '../../../Domain/UseCase/GetUserFeatures/GetUserFeatures'
|
|
import { BaseHttpController, results } from 'inversify-express-utils'
|
|
|
|
export class BaseFeaturesController extends BaseHttpController {
|
|
constructor(
|
|
protected doGetUserFeatures: GetUserFeatures,
|
|
private controllerContainer?: ControllerContainerInterface,
|
|
) {
|
|
super()
|
|
|
|
if (this.controllerContainer !== undefined) {
|
|
this.controllerContainer.register('auth.users.getFeatures', this.getFeatures.bind(this))
|
|
}
|
|
}
|
|
|
|
async getFeatures(request: Request, response: Response): Promise<results.JsonResult> {
|
|
if (request.params.userUuid !== response.locals.user.uuid) {
|
|
return this.json(
|
|
{
|
|
error: {
|
|
message: 'Operation not allowed.',
|
|
},
|
|
},
|
|
401,
|
|
)
|
|
}
|
|
|
|
const result = await this.doGetUserFeatures.execute({
|
|
userUuid: request.params.userUuid,
|
|
offline: false,
|
|
})
|
|
|
|
if (result.success) {
|
|
return this.json(result)
|
|
}
|
|
|
|
return this.json(result, 400)
|
|
}
|
|
}
|