Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

Commit

Permalink
intrn(server)!: return the created or found document
Browse files Browse the repository at this point in the history
  • Loading branch information
KennethTrecy committed Oct 15, 2022
1 parent 19f46a8 commit 5ed561f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions server/middlewares/miscellaneous/force_redirector.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Request, Response, NextFunction } from "!/types/dependent"

import redirect from "!/helpers/redirect"
import Middleware from "!/bases/middleware"
import RequestEnvironment from "$/singletons/request_environment"
Expand Down
7 changes: 5 additions & 2 deletions server/singletons/asynchronous_operation_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default class extends TransactionManager implements AsynchronousOperation
request: AuthenticatedRequest,
Manager: BaseManagerClass,
totalStepCount: number
): Promise<void> {
): Promise<Serializable> {
await this.initialize()
this.rawManager = new Manager({
"cache": request.cache,
Expand All @@ -38,7 +38,7 @@ export default class extends TransactionManager implements AsynchronousOperation
const hashedBody = await digest(request.body)
Log.trace("asynchronous", `digested body in ${request.url}`)

const possibleDocument = await this.manager.findOneOnColumn("token", hashedBody, {
let possibleDocument = await this.manager.findOneOnColumn("token", hashedBody, {
"constraints": {
"filter": {
"existence": "exists"
Expand All @@ -60,6 +60,7 @@ export default class extends TransactionManager implements AsynchronousOperation
"userID": Number(user.data.id)
})

possibleDocument = createdDocument
possibleResource = createdDocument.data
} else {
this.hasFound = true
Expand All @@ -74,6 +75,8 @@ export default class extends TransactionManager implements AsynchronousOperation
await this.destroySuccessfully()
await this.initialize()
Log.trace("asynchronous", "initialize asynchronous operation")

return possibleDocument
}

get isNew(): boolean { return !this.hasFound }
Expand Down
7 changes: 4 additions & 3 deletions t/helpers/setups/mock_requester.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { getMockReq as makeRequest, getMockRes as makeResponse } from "@jest-mock/express"

import type { Serializable } from "$/types/general"
import type { FieldRules } from "!/types/validation"
import type { Request, Response, NextFunction, BaseManagerClass } from "!/types/dependent"

Expand Down Expand Up @@ -89,11 +90,11 @@ export default class <T extends Request> extends RequestEnvironment {
unusedRequest: T,
Manager: BaseManagerClass,
totalStepCount: number
) => Promise<void>,
) => Promise<Serializable>,
Manager: BaseManagerClass,
totalStepCount: number
): Promise<void> {
await handle(this.request, Manager, totalStepCount)
): Promise<Serializable> {
return await handle(this.request, Manager, totalStepCount)
}

expectSuccess(): any {
Expand Down

0 comments on commit 5ed561f

Please sign in to comment.