©️
Cross api
En-US
En-US
  • Introduction
  • Compatibility
  • Extensions
  • Usage
    • Tools
      • Config
      • ListProvider
      • Language
      • Help
    • Structure
      • MakeApi
      • MakeModule
      • MakeProvider
      • Revert
  • Structure
    • Root
    • Src
    • @Types
    • Assets
    • Config
    • Dtos
    • Jobs
    • Keys
    • Middlewares
    • Modules
    • Routes
    • Shared
    • Utils
  • Services
    • Transactions
    • Exists
    • FindBy
    • FindIn
    • FindLike
    • FindAll
    • Create
    • CreateMany
    • Update
    • UpdateMany
    • Delete
    • DeleteMany
    • SoftDelete
    • SoftDeleteMany
  • Mappers
    • CloneAttribute
    • UpdateAttribute
    • PatchAttribute
    • UpdateString
    • PatchString
    • InsertAttribute
  • Providers
    • Cache
    • Crypto
    • Hash
    • Lead
    • MailTemplate
    • Mail
    • Queue
    • Notification
    • Storage
Powered by GitBook
On this page

Was this helpful?

  1. Mappers

UpdateString

Takes as parameter a stringified object and another object, converts, maps, and returns the stringified object with the updated properties. Non-entity-type properties are discarded.

No mapper:

const example: Example = {
  data: "{\"name\": \"example\",\"description\": \"this is an example\",\"extra\": \"\",\"size\": \"123\", \"price\": 100}",
}

const inputData: IExampleDTO = {
  name: undefined,
  description: "this is a new description",
  extra: "this is an extra",
  size: undefined,
  price: 20,
};

const updatedData = JSON.parse(example.data)

updatedData.name = inputData.name,
updatedData.description = inputData.description,
updatedData.extra = inputData.extra,
updatedData.size = inputData.size,
updatedData.price = inputData.price,

await this.examplesRepository.update(
  {
    ...example,
    data: JSON.stringify(updatedData),
  },
  trx,
);

output => example.data = "{\"name\": \"\",\"description\": \"this is a new description\",\"extra\": \"this is an extra\",\"size\": \"\", \"price\": 20}";

Using mapper:

import { updateString } from "@utils/mappers";

const example: Example = {
  data: "{\"name\": \"example\",\"description\": \"this is an example\",\"extra\": \"\",\"size\": \"123\", \"price\": 100}",
}

const inputData: IExampleDTO = {
  name: undefined,
  description: "this is a new description",
  extra: "this is an extra",
  size: undefined,
  price: 20,
};

await this.examplesRepository.update(
  {
    ...example,
    data: updateString(example.data, inputData),
  },
  trx,
);

output => example.data = "{\"name\": \"\",\"description\": \"this is a new description\",\"extra\": \"this is an extra\",\"size\": \"\", \"price\": 20}"

PreviousPatchAttributeNextPatchString

Was this helpful?