This repository has been archived by the owner on Sep 12, 2023. It is now read-only.
generated from KennethTrecy/web_template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
intrn(route): profanity filter create
- Loading branch information
Angelo Magtoto
committed
Oct 15, 2022
1 parent
eeb3358
commit 5e0b4b5
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import type { FieldRules } from "!/types/validation" | ||
import type { AuthenticatedRequest, Response } from "!/types/dependent" | ||
|
||
import Policy from "!/bases/policy" | ||
|
||
import Manager from "%/managers/profanity_filter" | ||
import JSONController from "!/controllers/json" | ||
import CreatedResponseInfo from "!/response_infos/created" | ||
|
||
import PermissionBasedPolicy from "!/policies/permission-based" | ||
import { profanity as permissionGroup } from "$/permissions/permission_list" | ||
import { | ||
CREATE | ||
} from "$/permissions/profanity_combinations" | ||
|
||
import string from "!/validators/base/string" | ||
import required from "!/validators/base/required" | ||
import length from "!/validators/comparison/length" | ||
import makeResourceDocumentRules from "!/rule_sets/make_resource_document" | ||
|
||
export default class extends JSONController { | ||
get filePath(): string { return __filename } | ||
|
||
get policy(): Policy { | ||
return new PermissionBasedPolicy(permissionGroup, [ | ||
CREATE | ||
]) | ||
} | ||
|
||
makeBodyRuleGenerator(unusedAuthenticatedRequest: AuthenticatedRequest): FieldRules { | ||
const attributes = { | ||
"word": { | ||
"constraints": { | ||
"length": { | ||
"maximum": 255, | ||
"minimum": 5 | ||
} | ||
}, | ||
"pipes": [ required, string, length ] | ||
} | ||
} | ||
|
||
return makeResourceDocumentRules("profanity_filter", attributes, { | ||
"isNew": true | ||
}) | ||
} | ||
|
||
async handle(request: AuthenticatedRequest, unusedResponse: Response) | ||
: Promise<CreatedResponseInfo> { | ||
const manager = new Manager(request) | ||
const word = await manager.create(request.body.data.attributes) | ||
|
||
return new CreatedResponseInfo(word) | ||
} | ||
} |