diff --git a/apps/jsonthing-api/CHANGELOG.md b/apps/jsonthing-api/CHANGELOG.md index b78c3c4..7276ff1 100644 --- a/apps/jsonthing-api/CHANGELOG.md +++ b/apps/jsonthing-api/CHANGELOG.md @@ -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/jsonthing-api@0.1.3...jsonthing-api@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/jsonthing-api@0.1.2...jsonthing-api@0.1.3) (2024-11-09) **Note:** Version bump only for package jsonthing-api diff --git a/apps/jsonthing-api/package.json b/apps/jsonthing-api/package.json index f4ed63e..4bd3043 100644 --- a/apps/jsonthing-api/package.json +++ b/apps/jsonthing-api/package.json @@ -1,6 +1,6 @@ { "name": "jsonthing-api", - "version": "0.1.3", + "version": "0.2.0", "description": "", "author": "", "private": true, diff --git a/apps/jsonthing-api/src/routes/docs/model/__snapshots__/docs.schama.spec.ts.snap b/apps/jsonthing-api/src/routes/docs/model/__snapshots__/docs.schama.spec.ts.snap index 86e0a41..a766f55 100644 --- a/apps/jsonthing-api/src/routes/docs/model/__snapshots__/docs.schama.spec.ts.snap +++ b/apps/jsonthing-api/src/routes/docs/model/__snapshots__/docs.schama.spec.ts.snap @@ -254,6 +254,14 @@ Schema { "required": true, "type": [Function], }, + "contentText": VirtualType { + "getters": [ + [Function], + ], + "options": {}, + "path": "contentText", + "setters": [], + }, "id": VirtualType { "getters": [ [Function], @@ -269,6 +277,14 @@ Schema { }, }, "virtuals": { + "contentText": VirtualType { + "getters": [ + [Function], + ], + "options": {}, + "path": "contentText", + "setters": [], + }, "id": VirtualType { "getters": [ [Function], diff --git a/apps/jsonthing-api/src/routes/docs/model/doc.schema.ts b/apps/jsonthing-api/src/routes/docs/model/doc.schema.ts index 0d64ce3..7396fef 100644 --- a/apps/jsonthing-api/src/routes/docs/model/doc.schema.ts +++ b/apps/jsonthing-api/src/routes/docs/model/doc.schema.ts @@ -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' @@ -31,6 +36,13 @@ export class Doc { }) content: Json + @Virtual({ + get: function () { + return JSON.stringify(this.content, null, 2) + }, + }) + contentText: string + id: string } diff --git a/apps/jsonthing-api/src/routes/docs/model/docs.schama.spec.ts b/apps/jsonthing-api/src/routes/docs/model/docs.schama.spec.ts index b819eeb..0ec4aa5 100644 --- a/apps/jsonthing-api/src/routes/docs/model/docs.schama.spec.ts +++ b/apps/jsonthing-api/src/routes/docs/model/docs.schama.spec.ts @@ -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 @@ -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(), }) }) }) @@ -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, }) }) })