-
Notifications
You must be signed in to change notification settings - Fork 1
/
750-microservice.bar.edit.sql
41 lines (38 loc) · 1.11 KB
/
750-microservice.bar.edit.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
ALTER PROCEDURE [microservice].[bar.edit] -- edit bar object
@bar [microservice].barTT READONLY, -- object to edit
@meta core.metaDataTT READONLY -- information for the user that makes the operation
AS
DECLARE @callParams XML
DECLARE @userId BIGINT = (SELECT [auth.actorId] FROM @meta)
DECLARE @barId BIGINT = (SELECT barId FROM @bar)
DECLARE @TranCounter INT = @@TRANCOUNT
BEGIN TRY
--ut-permission-check
IF @TranCounter = 0 BEGIN TRANSACTION
UPDATE
n
SET
n.barName = o.barName,
n.barDescription = o.barDescription
FROM
microservice.bar n
JOIN
@bar o ON o.barId = n.barId
IF @TranCounter = 0 COMMIT TRANSACTION
EXEC core.auditCall @procid = @@PROCID, @params = @callParams
EXEC [microservice].[bar.get] @barId = @barId
END TRY
BEGIN CATCH
IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION
IF error_number() NOT IN (2627)
BEGIN
EXEC [core].[error]
END
ELSE
BEGIN TRY
RAISERROR('Item already exists', 16, 1);
END TRY
BEGIN CATCH
EXEC [core].[error]
END CATCH
END CATCH