Skip to content

Commit

Permalink
Merge pull request #158 from contentstack/next
Browse files Browse the repository at this point in the history
Added Update content type method without fetch method
  • Loading branch information
harshithad0703 authored Jun 25, 2024
2 parents ba1c7c5 + 962cb95 commit 3daa860
Show file tree
Hide file tree
Showing 9 changed files with 3,242 additions and 11,967 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: actions/checkout@v2 # checkout the repo
- uses: actions/setup-node@v3
with:
node-version: '12.x'
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'
- run: npm ci # install packages
- run: npm run test:unit:report:json # run tests (configured to use jest-junit reporter)
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## [v1.16.2](https://github.com/contentstack/contentstack-management-javascript/tree/v1.16.2) (2024-06-24)
- Enhancement
- Added update content type without fetch method
## [v1.16.1](https://github.com/contentstack/contentstack-management-javascript/tree/v1.16.1) (2024-05-08)
- Fix
- Fix for `fs` not found issue in web build
Expand Down
60 changes: 60 additions & 0 deletions lib/stack/contentType/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,66 @@ export function ContentType (http, data = {}) {
*/
this.update = update(http, 'content_type')

/**
* @description The Update ContentType call lets you update the name and description of an existing ContentType.
* You can also update the JSON schema of a content type, including fields and different features associated with the content type.
* @memberof ContentType
* @func update
* @returns {Promise<ContentType.ContentType>} Promise for ContentType instance
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
* const data = {
* "content_type": {
* "title": "Page",
* "uid": "page",
* "schema": [{
* "display_name": "Title",
* "uid": "title",
* "data_type": "text",
* "field_metadata": {
* "_default": true
* },
* "unique": false,
* "mandatory": true,
* "multiple": false
* }
* ],
* "options": {
* "title": "title",
* "publishable": true,
* "is_page": true,
* "singleton": false,
* "sub_title": [
* "url"
* ],
* "url_pattern": "/:title",
* "url_prefix": "/"
* }
* }
* }
* }
* client.stack({ api_key: 'api_key'}).contentType('content_type_uid').updateCT(data)
* .then((contentType) => {
console.log(contentType)
* })
*/
this.updateCT = async (config) => {
try {
const headers = {
headers: { ...cloneDeep(this.stackHeaders) }
}
const response = await http.put(`${this.urlPath}`, config, headers)
if (response.data) {
return response.data
} else {
throw error(response)
}
} catch (err) {
throw error(err)
}
}

/**
* @description The Delete ContentType call is used to delete an existing ContentType permanently from your Stack.
* @memberof ContentType
Expand Down
Loading

0 comments on commit 3daa860

Please sign in to comment.