wip: default rotation

This commit is contained in:
Mo
2023-05-19 12:59:28 -05:00
parent 417b0257cf
commit c416ed6078
40 changed files with 571 additions and 131 deletions
@@ -0,0 +1,64 @@
import { ContactServiceInterface } from './../Domain/Contact/Service/ContactServiceInterface'
import { Request, Response } from 'express'
import { BaseHttpController, controller, httpPost, results, httpDelete } from 'inversify-express-utils'
import TYPES from '../Bootstrap/Types'
import { inject } from 'inversify'
import { ProjectorInterface } from '../Projection/ProjectorInterface'
import { Contact } from '../Domain/Contact/Model/Contact'
import { ContactProjection } from '../Projection/ContactProjection'
@controller('/contacts')
export class ContactsController extends BaseHttpController {
constructor(
@inject(TYPES.ContactService) private contactService: ContactServiceInterface,
@inject(TYPES.ContactProjector) private contactProjector: ProjectorInterface<Contact, ContactProjection>,
) {
super()
}
@httpPost('/', TYPES.AuthMiddleware)
public async createContact(
request: Request,
response: Response,
): Promise<results.NotFoundResult | results.JsonResult> {
const result = await this.contactService.createContact({
userUuid: response.locals.user.uuid,
contactUuid: request.body.contact_uuid,
contactPublicKey: request.body.contact_public_key,
})
if (!result) {
return this.errorResponse(500, 'Could not create contact')
}
return this.json({
contact: this.contactProjector.projectFull(result),
})
}
@httpDelete('/:contactUuid', TYPES.AuthMiddleware)
public async deleteContact(
request: Request,
response: Response,
): Promise<results.NotFoundResult | results.JsonResult> {
const result = await this.contactService.deleteContact({
originatorUuid: response.locals.user.uuid,
contactUuid: request.params.contactUuid,
})
if (!result) {
return this.errorResponse(500, 'Could not delete contact')
}
return this.json({ success: true })
}
private errorResponse(status: number, message?: string, tag?: string) {
return this.json(
{
error: { message, tag },
},
status,
)
}
}
@@ -86,7 +86,7 @@ export class GroupsController extends BaseHttpController {
return this.json({ success: true })
}
@httpPatch('/all-user-keys', TYPES.AuthMiddleware)
@httpPatch('/user-keys', TYPES.AuthMiddleware)
public async updateAllUserKeysOfUser(
request: Request,
response: Response,