Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Update content type method without fetch method #158

Merged
merged 4 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading