Files
svc-api-x/v1/resources/bookmark.cfc
T
2025-04-22 14:29:25 +03:00

72 lines
3.3 KiB
Plaintext

<cfcomponent extends="taffy.core.resource" taffy:uri="/bookmarks/bookmarks/{bookmarkUid}">
<cfsilent>
<cfimport prefix="m" taglib="../lib"/>
<cfset this.helper=CreateObject("component","lib.rest_api_helper")/><!---*** странно, почему мы его видим?---><!---вынести в апп?--->
</cfsilent>
<cffunction name="patch">
<cfargument name="bookmarkUid" type="string" required=true hint="type:guid"/>
<cfargument name="bookmark" type="string" required=false hint="type:string"/>
<cfargument name="descr" type="string" required=false hint="type:string (no cleanup here!)"/>
<cfargument name="url" type="string" required=false hint="type:string description: url"/><!--- чистить против XSS --->
<cfargument name="iconUrl" type="string" required=false hint="type:string description: url иконки"/><!--- чистить против XSS --->
<cfargument name="sort" type="string" required=false hint="type:integer description: целое число для сортировки"/>
<cfargument name="isEnabled" type="string" required=false hint="type:boolean description: вкл"/>
<!--- arguments.contragentId injected implicitly --->
<!--- arguments.usrId injected implicitly --->
<!--- ****** проверка уникальности --->
<cftry>
<cfset this.helper.keyExistsAndValid(arguments, "bookmarkUid", "guid")/>
<cfquery name="local.qSave">
update bookmark set
dt_updated=<cfqueryparam cfsqltype="cf_sql_timestamp" value="#Now()#"/>
,updater_id=<cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.usrId#"/>
<cfif structKeyExists(arguments,"bookmark")>
,bookmark=<cfqueryparam cfsqltype="cf_sql_varchar" value="#cleanInput(arguments.bookmark)#" />
</cfif>
<cfif structKeyExists(arguments,"descr")>
,descr=<cfqueryparam cfsqltype="cf_sql_varchar" value="#cleanInput(arguments.descr)#" />
</cfif>
<cfif structKeyExists(arguments,"url")>
,url=<cfqueryparam cfsqltype="cf_sql_varchar" value="#cleanInput(arguments.url)#" />
</cfif>
<cfif structKeyExists(arguments,"iconUrl")>
,icon_url=<cfqueryparam cfsqltype="cf_sql_varchar" value="#cleanInput(arguments.iconUrl)#" />
</cfif>
<cfif structKeyExists(arguments,"sort")>
,sort=<cfqueryparam cfsqltype="cf_sql_integer" value="#cleanInput(arguments.sort)#" />
</cfif>
<cfif structKeyExists(arguments,"isEnabled")>
,is_enabled=<cfqueryparam cfsqltype="cf_sql_bit" value="#cleanInput(arguments.isEnabled)#" />
</cfif>
where
contragent_id=<cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.contragentId#"/><!--- isolation --->
AND bookmark_uid=<cfqueryparam cfsqltype="cf_sql_other" value="#arguments.bookmarkUid#"/>;
--select @@rowcount as cnt;
</cfquery>
<!--- <cfif local.qSave.cnt EQ 0>
<cfreturn noData().withStatus(404, "Record Not Found") />
</cfif> --->
<cfcatch type="invalidParamValue">
<cfreturn representationOf(this.helper.formatBadRequestError(cfcatch)).withStatus(400)/>
</cfcatch>
</cftry>
<cfreturn noData().withStatus(204, "No Content") />
</cffunction>
<cffunction name="cleanInput">
<cfargument name="s" type="string"/>
<cfreturn htmlEditFormat(s)/>
</cffunction>
</cfcomponent>