Skip to content

Commit

Permalink
feat(api/docs): add contentText to docs schema (#105)
Browse files Browse the repository at this point in the history
* feat(api/docs): add contentText to docs schema

* chore(release): bump versions

 - [email protected]
  • Loading branch information
lharti authored Nov 12, 2024
1 parent e0e2229 commit 7aa6853
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 20 deletions.
11 changes: 11 additions & 0 deletions apps/jsonthing-api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [0.2.0](https://github.com/lharti/jsonthing/compare/[email protected]@0.2.0) (2024-11-12)


### Features

* **api/docs:** add contentText to docs schema ([39fe10b](https://github.com/lharti/jsonthing/commit/39fe10b8ee4682d7eea6b347df5c7ad5bbab5145))





## [0.1.3](https://github.com/lharti/jsonthing/compare/[email protected]@0.1.3) (2024-11-09)

**Note:** Version bump only for package jsonthing-api
Expand Down
2 changes: 1 addition & 1 deletion apps/jsonthing-api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jsonthing-api",
"version": "0.1.3",
"version": "0.2.0",
"description": "",
"author": "",
"private": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,14 @@ Schema {
"required": true,
"type": [Function],
},
"contentText": VirtualType {
"getters": [
[Function],
],
"options": {},
"path": "contentText",
"setters": [],
},
"id": VirtualType {
"getters": [
[Function],
Expand All @@ -269,6 +277,14 @@ Schema {
},
},
"virtuals": {
"contentText": VirtualType {
"getters": [
[Function],
],
"options": {},
"path": "contentText",
"setters": [],
},
"id": VirtualType {
"getters": [
[Function],
Expand Down
14 changes: 13 additions & 1 deletion apps/jsonthing-api/src/routes/docs/model/doc.schema.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { Json } from '@/common/types'
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'
import {
Prop,
Schema,
SchemaFactory,
Virtual,
} from '@nestjs/mongoose'
import mongoose, { ToObjectOptions } from 'mongoose'
import { DocsModel } from './doc.types'

Expand Down Expand Up @@ -31,6 +36,13 @@ export class Doc {
})
content: Json

@Virtual({
get: function () {
return JSON.stringify(this.content, null, 2)
},
})
contentText: string

id: string
}

Expand Down
31 changes: 13 additions & 18 deletions apps/jsonthing-api/src/routes/docs/model/docs.schama.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import {
createDocPayloadFixture,
docFixture,
} from '@/common/helpers/fixtures/doc.fixtures'
import { DocSchema, docsModel } from './doc.schema'

// eslint-disable-next-line @typescript-eslint/no-require-imports
Expand Down Expand Up @@ -71,18 +75,14 @@ describe('docSchema', () => {
it('should return pretty doc', async () => {
expect.assertions(1)

const random = Math.random().toString()

const doc = await docsModel.create({
title: random,
content: { test: random },
})
const doc = await docsModel.create(
createDocPayloadFixture,
)

expect(doc.toJSON()).toStrictEqual({
id: doc._id.toString(),
...docFixture,

content: { test: random },
title: random,
id: doc._id.toString(),
})
})
})
Expand All @@ -91,18 +91,13 @@ describe('docSchema', () => {
it('should return pretty doc', async () => {
expect.assertions(1)

const random = Math.random().toString()

const doc = await docsModel.create({
title: random,
content: { test: random },
})
const doc = await docsModel.create(
createDocPayloadFixture,
)

expect(doc.toJSON()).toStrictEqual({
...docFixture,
id: doc._id.toString(),

content: { test: random },
title: random,
})
})
})
Expand Down

0 comments on commit 7aa6853

Please sign in to comment.