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

Commit

Permalink
intrn(database): post tag transformer
Browse files Browse the repository at this point in the history
  • Loading branch information
Angelo Magtoto committed Oct 13, 2022
1 parent 60165a1 commit 33a6af6
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions database/transformers/post_tag.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import type { IncludedRelationships } from "%/types/independent"

import PostTag from "%/models/post_tag"
import Transformer from "%/transformers/base"
import TagTransformer from "%/transformers/tag"
import Serializer from "%/transformers/serializer"
import PostTransformer from "%/transformers/post"
import type { AttributesObject, TransformerOptions } from "%/types/dependent"

type Relationships = "post"|"tag"

export default class extends Transformer<PostTag, void> {
constructor({ included }: IncludedRelationships<Relationships> = {
"included": [ "post", "tag" ]
}) {
super("post_tag", [
included.indexOf("post") > -1
? {
"attribute": "post",
"transformer": new PostTransformer()
}
: null,
included.indexOf("tag") > -1
? {
"attribute": "tag",
"transformer": new TagTransformer()
}
: null
])
}


transform(model: PostTag|PostTag[], unusedOptions: TransformerOptions)
: AttributesObject {
const safeObject = Serializer.whitelist(model, [
"id"
])

return safeObject
}
}

0 comments on commit 33a6af6

Please sign in to comment.