diff --git a/web/backend/Database/Database.Migrations/scripts/02-functions/UDF_GetCountryIdByCode.sql b/web/backend/Database/Database.Migrations/scripts/02-functions/UDF_GetCountryIdByCode.sql index d8a4414c..c0ce88f1 100644 --- a/web/backend/Database/Database.Migrations/scripts/02-functions/UDF_GetCountryIdByCode.sql +++ b/web/backend/Database/Database.Migrations/scripts/02-functions/UDF_GetCountryIdByCode.sql @@ -1,18 +1,15 @@ -CREATE -OR -ALTER FUNCTION dbo.UDF_GetCountryIdByCode - ( +CREATE OR ALTER FUNCTION dbo.UDF_GetCountryIdByCode( @CountryCode NVARCHAR(2) - ) +) RETURNS UNIQUEIDENTIFIER - AS +AS BEGIN DECLARE -@CountryId UNIQUEIDENTIFIER; + @CountryId UNIQUEIDENTIFIER; -SELECT @CountryId = CountryID -FROM dbo.Country -WHERE ISO3166_1 = @CountryCode; + SELECT @CountryId = CountryID + FROM dbo.Country + WHERE ISO3166_1 = @CountryCode; -RETURN @CountryId; + RETURN @CountryId; END; diff --git a/web/backend/Database/Database.Migrations/scripts/02-functions/UDF_GetStateProvinceIdByCode.sql b/web/backend/Database/Database.Migrations/scripts/02-functions/UDF_GetStateProvinceIdByCode.sql index f07c30da..baea6063 100644 --- a/web/backend/Database/Database.Migrations/scripts/02-functions/UDF_GetStateProvinceIdByCode.sql +++ b/web/backend/Database/Database.Migrations/scripts/02-functions/UDF_GetStateProvinceIdByCode.sql @@ -1,16 +1,13 @@ -CREATE -OR -ALTER FUNCTION dbo.UDF_GetStateProvinceIdByCode - ( +CREATE OR ALTER FUNCTION dbo.UDF_GetStateProvinceIdByCode( @StateProvinceCode NVARCHAR(6) - ) +) RETURNS UNIQUEIDENTIFIER - AS +AS BEGIN DECLARE -@StateProvinceId UNIQUEIDENTIFIER; -SELECT @StateProvinceId = StateProvinceID -FROM dbo.StateProvince -WHERE ISO3166_2 = @StateProvinceCode; -RETURN @StateProvinceId; + @StateProvinceId UNIQUEIDENTIFIER; + SELECT @StateProvinceId = StateProvinceID + FROM dbo.StateProvince + WHERE ISO3166_2 = @StateProvinceCode; + RETURN @StateProvinceId; END; diff --git a/web/backend/Database/Database.Migrations/scripts/03-crud/01-UserAccount/USP_CreateUserAccount.sql b/web/backend/Database/Database.Migrations/scripts/03-crud/01-UserAccount/USP_CreateUserAccount.sql index 9de882ba..e8cc9351 100644 --- a/web/backend/Database/Database.Migrations/scripts/03-crud/01-UserAccount/USP_CreateUserAccount.sql +++ b/web/backend/Database/Database.Migrations/scripts/03-crud/01-UserAccount/USP_CreateUserAccount.sql @@ -1,34 +1,31 @@ -CREATE -OR -ALTER PROCEDURE usp_CreateUserAccount - ( +CREATE OR ALTER PROCEDURE usp_CreateUserAccount( @UserAccountId UNIQUEIDENTIFIER OUTPUT, - @Username VARCHAR (64), + @Username VARCHAR(64), @FirstName NVARCHAR(128), @LastName NVARCHAR(128), @DateOfBirth DATETIME, - @Email VARCHAR (128) - ) - AS + @Email VARCHAR(128) +) +AS BEGIN SET -NOCOUNT ON; + NOCOUNT ON; DECLARE -@Inserted TABLE (UserAccountID UNIQUEIDENTIFIER); + @Inserted TABLE + ( + UserAccountID UNIQUEIDENTIFIER + ); -INSERT INTO UserAccount -(Username, - FirstName, - LastName, - DateOfBirth, - Email) + INSERT INTO UserAccount + (Username, + FirstName, + LastName, + DateOfBirth, + Email) OUTPUT INSERTED.UserAccountID INTO @Inserted -VALUES - ( - @Username, @FirstName, @LastName, @DateOfBirth, @Email - ); + VALUES (@Username, @FirstName, @LastName, @DateOfBirth, @Email); -SELECT @UserAccountId = UserAccountID -FROM @Inserted; + SELECT @UserAccountId = UserAccountID + FROM @Inserted; END; diff --git a/web/backend/Database/Database.Migrations/scripts/03-crud/01-UserAccount/USP_DeleteUserAccount.sql b/web/backend/Database/Database.Migrations/scripts/03-crud/01-UserAccount/USP_DeleteUserAccount.sql index 86be614f..58f7b238 100644 --- a/web/backend/Database/Database.Migrations/scripts/03-crud/01-UserAccount/USP_DeleteUserAccount.sql +++ b/web/backend/Database/Database.Migrations/scripts/03-crud/01-UserAccount/USP_DeleteUserAccount.sql @@ -1,24 +1,20 @@ -CREATE -OR -ALTER PROCEDURE usp_DeleteUserAccount - ( +CREATE OR ALTER PROCEDURE usp_DeleteUserAccount( @UserAccountId UNIQUEIDENTIFIER - ) - AS +) +AS BEGIN - SET -NOCOUNT ON + SET NOCOUNT ON IF NOT EXISTS (SELECT 1 FROM UserAccount WHERE UserAccountId = @UserAccountId) -BEGIN - RAISERROR -('UserAccount with the specified ID does not exist.', 16, - 1); -ROLLBACK TRANSACTION - RETURN -END + BEGIN + RAISERROR + ('UserAccount with the specified ID does not exist.', 16, + 1); + ROLLBACK TRANSACTION + RETURN + END -DELETE -FROM UserAccount -WHERE UserAccountId = @UserAccountId; + DELETE + FROM UserAccount + WHERE UserAccountId = @UserAccountId; END; diff --git a/web/backend/Database/Database.Migrations/scripts/03-crud/01-UserAccount/USP_GetAllUserAccounts.sql b/web/backend/Database/Database.Migrations/scripts/03-crud/01-UserAccount/USP_GetAllUserAccounts.sql index 2e6a6f08..e23d90a0 100644 --- a/web/backend/Database/Database.Migrations/scripts/03-crud/01-UserAccount/USP_GetAllUserAccounts.sql +++ b/web/backend/Database/Database.Migrations/scripts/03-crud/01-UserAccount/USP_GetAllUserAccounts.sql @@ -1,19 +1,15 @@ -CREATE -OR -ALTER PROCEDURE usp_GetAllUserAccounts - AS +CREATE OR ALTER PROCEDURE usp_GetAllUserAccounts +AS BEGIN - SET -NOCOUNT ON; - -SELECT UserAccountID, - Username, - FirstName, - LastName, - Email, - CreatedAt, - UpdatedAt, - DateOfBirth, - Timer -FROM dbo.UserAccount; + SET NOCOUNT ON; + SELECT UserAccountID, + Username, + FirstName, + LastName, + Email, + CreatedAt, + UpdatedAt, + DateOfBirth, + Timer + FROM dbo.UserAccount; END; diff --git a/web/backend/Database/Database.Migrations/scripts/03-crud/01-UserAccount/USP_GetUserAccountByEmail.sql b/web/backend/Database/Database.Migrations/scripts/03-crud/01-UserAccount/USP_GetUserAccountByEmail.sql index 786de35a..3ac92b53 100644 --- a/web/backend/Database/Database.Migrations/scripts/03-crud/01-UserAccount/USP_GetUserAccountByEmail.sql +++ b/web/backend/Database/Database.Migrations/scripts/03-crud/01-UserAccount/USP_GetUserAccountByEmail.sql @@ -1,22 +1,20 @@ -CREATE -OR -ALTER PROCEDURE usp_GetUserAccountByEmail( - @Email VARCHAR (128) - ) - AS +CREATE OR ALTER PROCEDURE usp_GetUserAccountByEmail( + @Email VARCHAR(128) +) +AS BEGIN SET -NOCOUNT ON; + NOCOUNT ON; -SELECT UserAccountID, - Username, - FirstName, - LastName, - Email, - CreatedAt, - UpdatedAt, - DateOfBirth, - Timer -FROM dbo.UserAccount -WHERE Email = @Email; + SELECT UserAccountID, + Username, + FirstName, + LastName, + Email, + CreatedAt, + UpdatedAt, + DateOfBirth, + Timer + FROM dbo.UserAccount + WHERE Email = @Email; END; diff --git a/web/backend/Database/Database.Migrations/scripts/03-crud/01-UserAccount/USP_GetUserAccountById.sql b/web/backend/Database/Database.Migrations/scripts/03-crud/01-UserAccount/USP_GetUserAccountById.sql index 510a79f6..0a83ebf5 100644 --- a/web/backend/Database/Database.Migrations/scripts/03-crud/01-UserAccount/USP_GetUserAccountById.sql +++ b/web/backend/Database/Database.Migrations/scripts/03-crud/01-UserAccount/USP_GetUserAccountById.sql @@ -1,22 +1,20 @@ -CREATE -OR -ALTER PROCEDURE USP_GetUserAccountById( +CREATE OR ALTER PROCEDURE USP_GetUserAccountById( @UserAccountId UNIQUEIDENTIFIER - ) - AS +) +AS BEGIN SET -NOCOUNT ON; + NOCOUNT ON; -SELECT UserAccountID, - Username, - FirstName, - LastName, - Email, - CreatedAt, - UpdatedAt, - DateOfBirth, - Timer -FROM dbo.UserAccount -WHERE UserAccountID = @UserAccountId; + SELECT UserAccountID, + Username, + FirstName, + LastName, + Email, + CreatedAt, + UpdatedAt, + DateOfBirth, + Timer + FROM dbo.UserAccount + WHERE UserAccountID = @UserAccountId; END diff --git a/web/backend/Database/Database.Migrations/scripts/03-crud/01-UserAccount/USP_GetUserAccountByUsername.sql b/web/backend/Database/Database.Migrations/scripts/03-crud/01-UserAccount/USP_GetUserAccountByUsername.sql index 572ac352..2b8919d5 100644 --- a/web/backend/Database/Database.Migrations/scripts/03-crud/01-UserAccount/USP_GetUserAccountByUsername.sql +++ b/web/backend/Database/Database.Migrations/scripts/03-crud/01-UserAccount/USP_GetUserAccountByUsername.sql @@ -1,22 +1,20 @@ -CREATE -OR -ALTER PROCEDURE usp_GetUserAccountByUsername( - @Username VARCHAR (64) - ) - AS +CREATE OR ALTER PROCEDURE usp_GetUserAccountByUsername( + @Username VARCHAR(64) +) +AS BEGIN SET -NOCOUNT ON; + NOCOUNT ON; -SELECT UserAccountID, - Username, - FirstName, - LastName, - Email, - CreatedAt, - UpdatedAt, - DateOfBirth, - Timer -FROM dbo.UserAccount -WHERE Username = @Username; + SELECT UserAccountID, + Username, + FirstName, + LastName, + Email, + CreatedAt, + UpdatedAt, + DateOfBirth, + Timer + FROM dbo.UserAccount + WHERE Username = @Username; END; diff --git a/web/backend/Database/Database.Migrations/scripts/03-crud/01-UserAccount/USP_UpdateUserAccount.sql b/web/backend/Database/Database.Migrations/scripts/03-crud/01-UserAccount/USP_UpdateUserAccount.sql index 413d9236..be30d16e 100644 --- a/web/backend/Database/Database.Migrations/scripts/03-crud/01-UserAccount/USP_UpdateUserAccount.sql +++ b/web/backend/Database/Database.Migrations/scripts/03-crud/01-UserAccount/USP_UpdateUserAccount.sql @@ -1,30 +1,28 @@ -CREATE -OR -ALTER PROCEDURE usp_UpdateUserAccount( - @Username VARCHAR (64), +CREATE OR ALTER PROCEDURE usp_UpdateUserAccount( + @Username VARCHAR(64), @FirstName NVARCHAR(128), @LastName NVARCHAR(128), @DateOfBirth DATETIME, - @Email VARCHAR (128), + @Email VARCHAR(128), @UserAccountId UNIQUEIDENTIFIER - ) - AS +) +AS BEGIN SET -NOCOUNT ON; + NOCOUNT ON; -UPDATE UserAccount -SET Username = @Username, - FirstName = @FirstName, - LastName = @LastName, - DateOfBirth = @DateOfBirth, - Email = @Email -WHERE UserAccountId = @UserAccountId; + UPDATE UserAccount + SET Username = @Username, + FirstName = @FirstName, + LastName = @LastName, + DateOfBirth = @DateOfBirth, + Email = @Email + WHERE UserAccountId = @UserAccountId; -IF -@@ROWCOUNT = 0 -BEGIN + IF + @@ROWCOUNT = 0 + BEGIN THROW -50001, 'UserAccount with the specified ID does not exist.', 1; -END + 50001, 'UserAccount with the specified ID does not exist.', 1; + END END; diff --git a/web/backend/Database/Database.Migrations/scripts/03-crud/02-Auth/USP_GetUserCredentialByUserAccountId.sql b/web/backend/Database/Database.Migrations/scripts/03-crud/02-Auth/USP_GetUserCredentialByUserAccountId.sql index f387e92b..e962cb26 100644 --- a/web/backend/Database/Database.Migrations/scripts/03-crud/02-Auth/USP_GetUserCredentialByUserAccountId.sql +++ b/web/backend/Database/Database.Migrations/scripts/03-crud/02-Auth/USP_GetUserCredentialByUserAccountId.sql @@ -1,20 +1,18 @@ -CREATE -OR -ALTER PROCEDURE dbo.USP_GetActiveUserCredentialByUserAccountId( +CREATE OR ALTER PROCEDURE dbo.USP_GetActiveUserCredentialByUserAccountId( @UserAccountId UNIQUEIDENTIFIER - ) - AS +) +AS BEGIN SET -NOCOUNT ON; + NOCOUNT ON; -SELECT UserCredentialId, - UserAccountId, - Hash, - IsRevoked, - CreatedAt, - RevokedAt -FROM dbo.UserCredential -WHERE UserAccountId = @UserAccountId - AND IsRevoked = 0; + SELECT UserCredentialId, + UserAccountId, + Hash, + IsRevoked, + CreatedAt, + RevokedAt + FROM dbo.UserCredential + WHERE UserAccountId = @UserAccountId + AND IsRevoked = 0; END; \ No newline at end of file diff --git a/web/backend/Database/Database.Migrations/scripts/03-crud/02-Auth/USP_InvalidateUserCredential.sql b/web/backend/Database/Database.Migrations/scripts/03-crud/02-Auth/USP_InvalidateUserCredential.sql index c74118e1..b655f2f2 100644 --- a/web/backend/Database/Database.Migrations/scripts/03-crud/02-Auth/USP_InvalidateUserCredential.sql +++ b/web/backend/Database/Database.Migrations/scripts/03-crud/02-Auth/USP_InvalidateUserCredential.sql @@ -1,30 +1,28 @@ -CREATE -OR -ALTER PROCEDURE dbo.USP_InvalidateUserCredential( +CREATE OR ALTER PROCEDURE dbo.USP_InvalidateUserCredential( @UserAccountId_ UNIQUEIDENTIFIER - ) - AS +) +AS BEGIN SET -NOCOUNT ON; + NOCOUNT ON; SET -XACT_ABORT ON; + XACT_ABORT ON; -BEGIN -TRANSACTION; + BEGIN + TRANSACTION; -EXEC dbo.USP_GetUserAccountByID @UserAccountId = @UserAccountId_; + EXEC dbo.USP_GetUserAccountByID @UserAccountId = @UserAccountId_; IF -@@ROWCOUNT = 0 + @@ROWCOUNT = 0 THROW 50001, 'User account not found', 1; -- invalidate all other credentials by setting them to revoked -UPDATE dbo.UserCredential -SET IsRevoked = 1, - RevokedAt = GETDATE() -WHERE UserAccountId = @UserAccountId_ - AND IsRevoked != 1; + UPDATE dbo.UserCredential + SET IsRevoked = 1, + RevokedAt = GETDATE() + WHERE UserAccountId = @UserAccountId_ + AND IsRevoked != 1; -COMMIT TRANSACTION; + COMMIT TRANSACTION; END; \ No newline at end of file diff --git a/web/backend/Database/Database.Migrations/scripts/03-crud/02-Auth/USP_RegisterUser.sql b/web/backend/Database/Database.Migrations/scripts/03-crud/02-Auth/USP_RegisterUser.sql index a85f8e45..4c2a4597 100644 --- a/web/backend/Database/Database.Migrations/scripts/03-crud/02-Auth/USP_RegisterUser.sql +++ b/web/backend/Database/Database.Migrations/scripts/03-crud/02-Auth/USP_RegisterUser.sql @@ -1,27 +1,25 @@ -CREATE -OR -ALTER PROCEDURE dbo.USP_RegisterUser( - @Username VARCHAR (64), +CREATE OR ALTER PROCEDURE dbo.USP_RegisterUser( + @Username VARCHAR(64), @FirstName NVARCHAR(128), @LastName NVARCHAR(128), @DateOfBirth DATETIME, - @Email VARCHAR (128), + @Email VARCHAR(128), @Hash NVARCHAR(MAX) - ) - AS +) +AS BEGIN SET -NOCOUNT ON; + NOCOUNT ON; SET -XACT_ABORT ON; + XACT_ABORT ON; DECLARE -@UserAccountId_ UNIQUEIDENTIFIER; + @UserAccountId_ UNIQUEIDENTIFIER; -BEGIN -TRANSACTION; + BEGIN + TRANSACTION; -EXEC usp_CreateUserAccount + EXEC usp_CreateUserAccount @UserAccountId = @UserAccountId_ OUTPUT, @Username = @Username, @FirstName = @FirstName, @@ -30,23 +28,23 @@ EXEC usp_CreateUserAccount @Email = @Email; IF -@UserAccountId_ IS NULL -BEGIN + @UserAccountId_ IS NULL + BEGIN THROW -50000, 'Failed to create user account.', 1; -END + 50000, 'Failed to create user account.', 1; + END -INSERT INTO dbo.UserCredential - (UserAccountId, Hash) -VALUES (@UserAccountId_, @Hash); + INSERT INTO dbo.UserCredential + (UserAccountId, Hash) + VALUES (@UserAccountId_, @Hash); -IF -@@ROWCOUNT = 0 -BEGIN + IF + @@ROWCOUNT = 0 + BEGIN THROW -50002, 'Failed to create user credential.', 1; -END -COMMIT TRANSACTION; + 50002, 'Failed to create user credential.', 1; + END + COMMIT TRANSACTION; -SELECT @UserAccountId_ AS UserAccountId; + SELECT @UserAccountId_ AS UserAccountId; END diff --git a/web/backend/Database/Database.Migrations/scripts/03-crud/02-Auth/USP_RotateUserCredential.sql b/web/backend/Database/Database.Migrations/scripts/03-crud/02-Auth/USP_RotateUserCredential.sql index e00317a9..3408b182 100644 --- a/web/backend/Database/Database.Migrations/scripts/03-crud/02-Auth/USP_RotateUserCredential.sql +++ b/web/backend/Database/Database.Migrations/scripts/03-crud/02-Auth/USP_RotateUserCredential.sql @@ -1,33 +1,31 @@ -CREATE -OR -ALTER PROCEDURE dbo.USP_RotateUserCredential( +CREATE OR ALTER PROCEDURE dbo.USP_RotateUserCredential( @UserAccountId_ UNIQUEIDENTIFIER, @Hash NVARCHAR(MAX) - ) - AS +) +AS BEGIN SET -NOCOUNT ON; + NOCOUNT ON; SET -XACT_ABORT ON; -BEGIN -TRANSACTION; + XACT_ABORT ON; + BEGIN + TRANSACTION; -EXEC USP_GetUserAccountByID @UserAccountId = @UserAccountId_ + EXEC USP_GetUserAccountByID @UserAccountId = @UserAccountId_ IF @@ROWCOUNT = 0 THROW 50001, 'User account not found', 1; -- invalidate all other credentials -- set them to revoked -UPDATE dbo.UserCredential -SET IsRevoked = 1, - RevokedAt = GETDATE() -WHERE UserAccountId = @UserAccountId_; + UPDATE dbo.UserCredential + SET IsRevoked = 1, + RevokedAt = GETDATE() + WHERE UserAccountId = @UserAccountId_; -INSERT INTO dbo.UserCredential - (UserAccountId, Hash) -VALUES (@UserAccountId_, @Hash); + INSERT INTO dbo.UserCredential + (UserAccountId, Hash) + VALUES (@UserAccountId_, @Hash); END; \ No newline at end of file diff --git a/web/backend/Database/Database.Migrations/scripts/03-crud/03-UserVerification/USP_AddUserVerification.sql b/web/backend/Database/Database.Migrations/scripts/03-crud/03-UserVerification/USP_AddUserVerification.sql index 23a9e785..bdfe538d 100644 --- a/web/backend/Database/Database.Migrations/scripts/03-crud/03-UserVerification/USP_AddUserVerification.sql +++ b/web/backend/Database/Database.Migrations/scripts/03-crud/03-UserVerification/USP_AddUserVerification.sql @@ -1,29 +1,27 @@ -CREATE -OR -ALTER PROCEDURE dbo.USP_CreateUserVerification @UserAccountID_ UNIQUEIDENTIFIER, - @VerificationDateTime DATETIME = NULL - AS +CREATE OR ALTER PROCEDURE dbo.USP_CreateUserVerification @UserAccountID_ UNIQUEIDENTIFIER, + @VerificationDateTime DATETIME = NULL +AS BEGIN SET -NOCOUNT ON; + NOCOUNT ON; SET -XACT_ABORT ON; + XACT_ABORT ON; IF -@VerificationDateTime IS NULL + @VerificationDateTime IS NULL SET @VerificationDateTime = GETDATE(); -BEGIN -TRANSACTION; + BEGIN + TRANSACTION; -EXEC USP_GetUserAccountByID @UserAccountId = @UserAccountID_; + EXEC USP_GetUserAccountByID @UserAccountId = @UserAccountID_; IF -@@ROWCOUNT = 0 + @@ROWCOUNT = 0 THROW 50001, 'Could not find a user with that id', 1; -INSERT INTO dbo.UserVerification - (UserAccountId, VerificationDateTime) -VALUES (@UserAccountID_, @VerificationDateTime); + INSERT INTO dbo.UserVerification + (UserAccountId, VerificationDateTime) + VALUES (@UserAccountID_, @VerificationDateTime); -COMMIT TRANSACTION; + COMMIT TRANSACTION; END diff --git a/web/backend/Database/Database.Migrations/scripts/03-crud/04-Location/USP_CreateCity.sql b/web/backend/Database/Database.Migrations/scripts/03-crud/04-Location/USP_CreateCity.sql index ef82d90e..e95a4960 100644 --- a/web/backend/Database/Database.Migrations/scripts/03-crud/04-Location/USP_CreateCity.sql +++ b/web/backend/Database/Database.Migrations/scripts/03-crud/04-Location/USP_CreateCity.sql @@ -1,40 +1,38 @@ -CREATE -OR -ALTER PROCEDURE dbo.USP_CreateCity( +CREATE OR ALTER PROCEDURE dbo.USP_CreateCity( @CityName NVARCHAR(100), @StateProvinceCode NVARCHAR(6) - ) - AS +) +AS BEGIN SET -NOCOUNT ON; + NOCOUNT ON; SET -XACT_ABORT ON; + XACT_ABORT ON; -BEGIN -TRANSACTION + BEGIN + TRANSACTION DECLARE -@StateProvinceId UNIQUEIDENTIFIER = dbo.UDF_GetStateProvinceIdByCode(@StateProvinceCode); + @StateProvinceId UNIQUEIDENTIFIER = dbo.UDF_GetStateProvinceIdByCode(@StateProvinceCode); IF -@StateProvinceId IS NULL -BEGIN + @StateProvinceId IS NULL + BEGIN THROW -50001, 'State/province does not exist', 1; -END + 50001, 'State/province does not exist', 1; + END IF -EXISTS (SELECT 1 - FROM dbo.City - WHERE CityName = @CityName - AND StateProvinceID = @StateProvinceId) -BEGIN + EXISTS (SELECT 1 + FROM dbo.City + WHERE CityName = @CityName + AND StateProvinceID = @StateProvinceId) + BEGIN THROW -50002, 'City already exists.', 1; -END + 50002, 'City already exists.', 1; + END -INSERT INTO dbo.City - (StateProvinceID, CityName) -VALUES (@StateProvinceId, @CityName); -COMMIT TRANSACTION + INSERT INTO dbo.City + (StateProvinceID, CityName) + VALUES (@StateProvinceId, @CityName); + COMMIT TRANSACTION END; diff --git a/web/backend/Database/Database.Migrations/scripts/03-crud/04-Location/USP_CreateCountry.sql b/web/backend/Database/Database.Migrations/scripts/03-crud/04-Location/USP_CreateCountry.sql index acad2459..0f60e353 100644 --- a/web/backend/Database/Database.Migrations/scripts/03-crud/04-Location/USP_CreateCountry.sql +++ b/web/backend/Database/Database.Migrations/scripts/03-crud/04-Location/USP_CreateCountry.sql @@ -1,26 +1,24 @@ -CREATE -OR -ALTER PROCEDURE dbo.USP_CreateCountry( +CREATE OR ALTER PROCEDURE dbo.USP_CreateCountry( @CountryName NVARCHAR(100), @ISO3166_1 NVARCHAR(2) - ) - AS +) +AS BEGIN SET -NOCOUNT ON; + NOCOUNT ON; SET -XACT_ABORT ON; -BEGIN -TRANSACTION; + XACT_ABORT ON; + BEGIN + TRANSACTION; IF -EXISTS (SELECT 1 - FROM dbo.Country - WHERE ISO3166_1 = @ISO3166_1) + EXISTS (SELECT 1 + FROM dbo.Country + WHERE ISO3166_1 = @ISO3166_1) THROW 50001, 'Country already exists', 1; -INSERT INTO dbo.Country - (CountryName, ISO3166_1) -VALUES (@CountryName, @ISO3166_1); -COMMIT TRANSACTION; + INSERT INTO dbo.Country + (CountryName, ISO3166_1) + VALUES (@CountryName, @ISO3166_1); + COMMIT TRANSACTION; END; diff --git a/web/backend/Database/Database.Migrations/scripts/03-crud/04-Location/USP_CreateStateProvince.sql b/web/backend/Database/Database.Migrations/scripts/03-crud/04-Location/USP_CreateStateProvince.sql index a850ac8a..893e52e2 100644 --- a/web/backend/Database/Database.Migrations/scripts/03-crud/04-Location/USP_CreateStateProvince.sql +++ b/web/backend/Database/Database.Migrations/scripts/03-crud/04-Location/USP_CreateStateProvince.sql @@ -1,34 +1,32 @@ -CREATE -OR -ALTER PROCEDURE dbo.USP_CreateStateProvince( +CREATE OR ALTER PROCEDURE dbo.USP_CreateStateProvince( @StateProvinceName NVARCHAR(100), @ISO3166_2 NVARCHAR(6), @CountryCode NVARCHAR(2) - ) - AS +) +AS BEGIN SET -NOCOUNT ON; + NOCOUNT ON; SET -XACT_ABORT ON; + XACT_ABORT ON; IF -EXISTS (SELECT 1 - FROM dbo.StateProvince - WHERE ISO3166_2 = @ISO3166_2) + EXISTS (SELECT 1 + FROM dbo.StateProvince + WHERE ISO3166_2 = @ISO3166_2) RETURN; DECLARE -@CountryId UNIQUEIDENTIFIER = dbo.UDF_GetCountryIdByCode(@CountryCode); + @CountryId UNIQUEIDENTIFIER = dbo.UDF_GetCountryIdByCode(@CountryCode); IF -@CountryId IS NULL -BEGIN - THROW -50001, 'Country does not exist', 1; + @CountryId IS NULL + BEGIN + THROW + 50001, 'Country does not exist', 1; -END + END -INSERT INTO dbo.StateProvince - (StateProvinceName, ISO3166_2, CountryID) -VALUES (@StateProvinceName, @ISO3166_2, @CountryId); + INSERT INTO dbo.StateProvince + (StateProvinceName, ISO3166_2, CountryID) + VALUES (@StateProvinceName, @ISO3166_2, @CountryId); END; diff --git a/web/backend/Database/Database.Migrations/scripts/03-crud/05-Breweries/USP_CreateBrewery.sql b/web/backend/Database/Database.Migrations/scripts/03-crud/05-Breweries/USP_CreateBrewery.sql index bfb29f8d..999c1588 100644 --- a/web/backend/Database/Database.Migrations/scripts/03-crud/05-Breweries/USP_CreateBrewery.sql +++ b/web/backend/Database/Database.Migrations/scripts/03-crud/05-Breweries/USP_CreateBrewery.sql @@ -1,6 +1,4 @@ -CREATE -OR -ALTER PROCEDURE dbo.USP_CreateBrewery( +CREATE OR ALTER PROCEDURE dbo.USP_CreateBrewery( @BreweryName NVARCHAR(256), @Description NVARCHAR(512), @PostedByID UNIQUEIDENTIFIER, @@ -9,53 +7,53 @@ ALTER PROCEDURE dbo.USP_CreateBrewery( @AddressLine2 NVARCHAR(256) = NULL, @PostalCode NVARCHAR(20), @Coordinates GEOGRAPHY = NULL - ) - AS +) +AS BEGIN SET -NOCOUNT ON; + NOCOUNT ON; SET -XACT_ABORT ON; + XACT_ABORT ON; IF -@BreweryName IS NULL + @BreweryName IS NULL THROW 50001, 'Brewery name cannot be null.', 1; IF -@Description IS NULL + @Description IS NULL THROW 50002, 'Brewery description cannot be null.', 1; IF -NOT EXISTS (SELECT 1 - FROM dbo.UserAccount - WHERE UserAccountID = @PostedByID) + NOT EXISTS (SELECT 1 + FROM dbo.UserAccount + WHERE UserAccountID = @PostedByID) THROW 50404, 'User not found.', 1; IF -NOT EXISTS (SELECT 1 - FROM dbo.City - WHERE CityID = @CityID) + NOT EXISTS (SELECT 1 + FROM dbo.City + WHERE CityID = @CityID) THROW 50404, 'City not found.', 1; DECLARE -@NewBreweryID UNIQUEIDENTIFIER = NEWID(); + @NewBreweryID UNIQUEIDENTIFIER = NEWID(); DECLARE -@NewBrewerLocationID UNIQUEIDENTIFIER = NEWID(); + @NewBrewerLocationID UNIQUEIDENTIFIER = NEWID(); -BEGIN -TRANSACTION; + BEGIN + TRANSACTION; -INSERT INTO dbo.BreweryPost - (BreweryPostID, BreweryName, Description, PostedByID) -VALUES (@NewBreweryID, @BreweryName, @Description, @PostedByID); + INSERT INTO dbo.BreweryPost + (BreweryPostID, BreweryName, Description, PostedByID) + VALUES (@NewBreweryID, @BreweryName, @Description, @PostedByID); -INSERT INTO dbo.BreweryPostLocation -(BreweryPostLocationID, BreweryPostID, CityID, AddressLine1, AddressLine2, PostalCode, Coordinates) -VALUES (@NewBrewerLocationID, @NewBreweryID, @CityID, @AddressLine1, @AddressLine2, @PostalCode, @Coordinates); + INSERT INTO dbo.BreweryPostLocation + (BreweryPostLocationID, BreweryPostID, CityID, AddressLine1, AddressLine2, PostalCode, Coordinates) + VALUES (@NewBrewerLocationID, @NewBreweryID, @CityID, @AddressLine1, @AddressLine2, @PostalCode, @Coordinates); -COMMIT TRANSACTION; + COMMIT TRANSACTION; -SELECT @NewBreweryID AS BreweryPostID, - @NewBrewerLocationID AS BreweryPostLocationID; + SELECT @NewBreweryID AS BreweryPostID, + @NewBrewerLocationID AS BreweryPostLocationID; END diff --git a/web/backend/Database/Database.Migrations/scripts/03-crud/05-Breweries/USP_DeleteBrewery.sql b/web/backend/Database/Database.Migrations/scripts/03-crud/05-Breweries/USP_DeleteBrewery.sql index 4b83179a..b4bf3905 100644 --- a/web/backend/Database/Database.Migrations/scripts/03-crud/05-Breweries/USP_DeleteBrewery.sql +++ b/web/backend/Database/Database.Migrations/scripts/03-crud/05-Breweries/USP_DeleteBrewery.sql @@ -1,20 +1,17 @@ -CREATE -OR -ALTER PROCEDURE dbo.USP_DeleteBrewery - @BreweryPostID UNIQUEIDENTIFIER - AS +CREATE OR ALTER PROCEDURE dbo.USP_DeleteBrewery @BreweryPostID UNIQUEIDENTIFIER +AS BEGIN SET -NOCOUNT ON; + NOCOUNT ON; IF -NOT EXISTS (SELECT 1 - FROM dbo.BreweryPost - WHERE BreweryPostID = @BreweryPostID) + NOT EXISTS (SELECT 1 + FROM dbo.BreweryPost + WHERE BreweryPostID = @BreweryPostID) THROW 50404, 'Brewery not found.', 1; -- BreweryPostLocation and BreweryPostPhoto cascade-delete with their parent BreweryPost. -DELETE -FROM dbo.BreweryPost -WHERE BreweryPostID = @BreweryPostID; + DELETE + FROM dbo.BreweryPost + WHERE BreweryPostID = @BreweryPostID; END diff --git a/web/backend/Database/Database.Migrations/scripts/03-crud/05-Breweries/USP_GetAllBreweries.sql b/web/backend/Database/Database.Migrations/scripts/03-crud/05-Breweries/USP_GetAllBreweries.sql index 4f92e20d..208be24f 100644 --- a/web/backend/Database/Database.Migrations/scripts/03-crud/05-Breweries/USP_GetAllBreweries.sql +++ b/web/backend/Database/Database.Migrations/scripts/03-crud/05-Breweries/USP_GetAllBreweries.sql @@ -1,30 +1,28 @@ -CREATE -OR -ALTER PROCEDURE dbo.USP_GetAllBreweries( +CREATE OR ALTER PROCEDURE dbo.USP_GetAllBreweries( @Limit INT = NULL, @Offset INT = NULL - ) - AS +) +AS BEGIN SET -NOCOUNT ON; + NOCOUNT ON; -SELECT bp.BreweryPostID, - bp.PostedByID, - bp.BreweryName, - bp.Description, - bp.CreatedAt, - bp.UpdatedAt, - bp.Timer, - bpl.BreweryPostLocationID, - bpl.CityID, - bpl.AddressLine1, - bpl.AddressLine2, - bpl.PostalCode, - bpl.Coordinates -FROM dbo.BreweryPost bp - LEFT JOIN dbo.BreweryPostLocation bpl - ON bp.BreweryPostID = bpl.BreweryPostID -ORDER BY bp.CreatedAt DESC -OFFSET ISNULL(@Offset, 0) ROWS FETCH NEXT ISNULL(@Limit, 2147483647) ROWS ONLY; + SELECT bp.BreweryPostID, + bp.PostedByID, + bp.BreweryName, + bp.Description, + bp.CreatedAt, + bp.UpdatedAt, + bp.Timer, + bpl.BreweryPostLocationID, + bpl.CityID, + bpl.AddressLine1, + bpl.AddressLine2, + bpl.PostalCode, + bpl.Coordinates + FROM dbo.BreweryPost bp + LEFT JOIN dbo.BreweryPostLocation bpl + ON bp.BreweryPostID = bpl.BreweryPostID + ORDER BY bp.CreatedAt DESC + OFFSET ISNULL(@Offset, 0) ROWS FETCH NEXT ISNULL(@Limit, 2147483647) ROWS ONLY; END diff --git a/web/backend/Database/Database.Migrations/scripts/03-crud/05-Breweries/USP_GetBreweryById.sql b/web/backend/Database/Database.Migrations/scripts/03-crud/05-Breweries/USP_GetBreweryById.sql index 730adf36..25425efc 100644 --- a/web/backend/Database/Database.Migrations/scripts/03-crud/05-Breweries/USP_GetBreweryById.sql +++ b/web/backend/Database/Database.Migrations/scripts/03-crud/05-Breweries/USP_GetBreweryById.sql @@ -1,11 +1,9 @@ -CREATE -OR -ALTER PROCEDURE dbo.USP_GetBreweryById @BreweryPostID UNIQUEIDENTIFIER - AS +CREATE OR ALTER PROCEDURE dbo.USP_GetBreweryById @BreweryPostID UNIQUEIDENTIFIER +AS BEGIN -SELECT * -FROM BreweryPost bp - INNER JOIN BreweryPostLocation bpl - ON bp.BreweryPostID = bpl.BreweryPostID -WHERE bp.BreweryPostID = @BreweryPostID; + SELECT * + FROM BreweryPost bp + INNER JOIN BreweryPostLocation bpl + ON bp.BreweryPostID = bpl.BreweryPostID + WHERE bp.BreweryPostID = @BreweryPostID; END \ No newline at end of file diff --git a/web/backend/Database/Database.Migrations/scripts/03-crud/05-Breweries/USP_UpdateBrewery.sql b/web/backend/Database/Database.Migrations/scripts/03-crud/05-Breweries/USP_UpdateBrewery.sql index cd7d43df..3f3ba76c 100644 --- a/web/backend/Database/Database.Migrations/scripts/03-crud/05-Breweries/USP_UpdateBrewery.sql +++ b/web/backend/Database/Database.Migrations/scripts/03-crud/05-Breweries/USP_UpdateBrewery.sql @@ -1,6 +1,4 @@ -CREATE -OR -ALTER PROCEDURE dbo.USP_UpdateBrewery( +CREATE OR ALTER PROCEDURE dbo.USP_UpdateBrewery( @BreweryPostID UNIQUEIDENTIFIER, @BreweryName NVARCHAR(256), @Description NVARCHAR(512), @@ -10,70 +8,70 @@ ALTER PROCEDURE dbo.USP_UpdateBrewery( @AddressLine2 NVARCHAR(256) = NULL, @PostalCode NVARCHAR(20) = NULL, @Coordinates GEOGRAPHY = NULL - ) - AS +) +AS BEGIN SET -NOCOUNT ON; + NOCOUNT ON; SET -XACT_ABORT ON; + XACT_ABORT ON; IF -@BreweryName IS NULL + @BreweryName IS NULL THROW 50001, 'Brewery name cannot be null.', 1; IF -@Description IS NULL + @Description IS NULL THROW 50002, 'Brewery description cannot be null.', 1; IF -NOT EXISTS (SELECT 1 - FROM dbo.BreweryPost - WHERE BreweryPostID = @BreweryPostID) + NOT EXISTS (SELECT 1 + FROM dbo.BreweryPost + WHERE BreweryPostID = @BreweryPostID) THROW 50404, 'Brewery not found.', 1; IF -@CityID IS NOT NULL AND NOT EXISTS (SELECT 1 + @CityID IS NOT NULL AND NOT EXISTS (SELECT 1 FROM dbo.City WHERE CityID = @CityID) THROW 50404, 'City not found.', 1; -BEGIN -TRANSACTION; + BEGIN + TRANSACTION; -UPDATE dbo.BreweryPost -SET BreweryName = @BreweryName, - Description = @Description, - UpdatedAt = GETDATE() -WHERE BreweryPostID = @BreweryPostID; + UPDATE dbo.BreweryPost + SET BreweryName = @BreweryName, + Description = @Description, + UpdatedAt = GETDATE() + WHERE BreweryPostID = @BreweryPostID; -IF -@CityID IS NULL -BEGIN + IF + @CityID IS NULL + BEGIN -- No location supplied: clear any existing location for this brewery. -DELETE -FROM dbo.BreweryPostLocation -WHERE BreweryPostID = @BreweryPostID; -END -ELSE IF EXISTS (SELECT 1 - FROM dbo.BreweryPostLocation - WHERE BreweryPostID = @BreweryPostID) -BEGIN -UPDATE dbo.BreweryPostLocation -SET CityID = @CityID, - AddressLine1 = @AddressLine1, - AddressLine2 = @AddressLine2, - PostalCode = @PostalCode, - Coordinates = @Coordinates -WHERE BreweryPostID = @BreweryPostID; -END -ELSE -BEGIN -INSERT INTO dbo.BreweryPostLocation -(BreweryPostLocationID, BreweryPostID, CityID, AddressLine1, AddressLine2, PostalCode, Coordinates) -VALUES (ISNULL(@BreweryPostLocationID, NEWID()), @BreweryPostID, @CityID, @AddressLine1, @AddressLine2, - @PostalCode, @Coordinates); -END - -COMMIT TRANSACTION; + DELETE + FROM dbo.BreweryPostLocation + WHERE BreweryPostID = @BreweryPostID; + END + ELSE + IF EXISTS (SELECT 1 + FROM dbo.BreweryPostLocation + WHERE BreweryPostID = @BreweryPostID) + BEGIN + UPDATE dbo.BreweryPostLocation + SET CityID = @CityID, + AddressLine1 = @AddressLine1, + AddressLine2 = @AddressLine2, + PostalCode = @PostalCode, + Coordinates = @Coordinates + WHERE BreweryPostID = @BreweryPostID; + END + ELSE + BEGIN + INSERT INTO dbo.BreweryPostLocation + (BreweryPostLocationID, BreweryPostID, CityID, AddressLine1, AddressLine2, PostalCode, Coordinates) + VALUES (ISNULL(@BreweryPostLocationID, NEWID()), @BreweryPostID, @CityID, @AddressLine1, @AddressLine2, + @PostalCode, @Coordinates); + END + COMMIT TRANSACTION; END