add openhack files

This commit is contained in:
Ryan Peters
2022-11-03 16:41:13 -04:00
commit b2c9f7e29f
920 changed files with 118861 additions and 0 deletions

View File

@ -0,0 +1,35 @@
'use strict';
var Mockgen = require('../mockgen.js');
/**
* Operations on /healthcheck/user
*/
module.exports = {
/**
* summary:
* description: Returns healthcheck for systems looking to ensure API is up and operational
* parameters:
* produces:
* responses: 200, default
* operationId:
*/
get: {
200: function (req, res, callback) {
res.json({
message: 'Userprofile Service Healthcheck',
status: 'healthy'
});
callback;
},
default: function (req, res, callback) {
/**
* Using mock data generator module.
* Replace this by actual data for the api.
*/
Mockgen().responses({
path: '/healthcheck/user',
operation: 'get',
response: 'default'
}, callback);
}
}
};

View File

@ -0,0 +1,13 @@
'use strict';
var Swagmock = require('swagmock');
var Path = require('path');
var apiPath = Path.resolve(__dirname, '../config/swagger.json');
var mockgen;
module.exports = function () {
/**
* Cached mock generator
*/
mockgen = mockgen || Swagmock(apiPath);
return mockgen;
};

View File

@ -0,0 +1,66 @@
exports.INSERT_USER_PROFILE =
`INSERT INTO userprofiles \
(\
Id,\
FirstName,\
LastName,\
UserId,\
ProfilePictureUri,\
Rating,\
Ranking,\
TotalDistance,\
TotalTrips,\
TotalTime,\
HardStops,\
HardAccelerations,\
FuelConsumption,\
MaxSpeed,\
CreatedAt,\
UpdatedAt,\
Deleted\
) \
SELECT \
Id,\
FirstName,\
LastName,\
UserId,\
ProfilePictureUri,\
Rating,\
Ranking,\
TotalDistance,\
TotalTrips,\
TotalTime,\
HardStops,\
HardAccelerations,\
FuelConsumption,\
MaxSpeed,\
GETDATE(),\
GETDATE(),\
Deleted \
FROM OPENJSON(@UserProfileJson) \
WITH (
Id nvarchar(128),\
FirstName nvarchar(max),\
LastName nvarchar(max),\
UserId nvarchar(max),\
ProfilePictureUri nvarchar(max),\
Rating int,\
Ranking int,\
TotalDistance float(53),\
TotalTrips bigint,\
TotalTime bigint,\
HardStops bigint,\
HardAccelerations bigint,\
FuelConsumption float(53),\
MaxSpeed float(53),\
Deleted bit\
) AS JSON`;
exports.SELECT_USER_PROFILE_BY_ID=
'select * from userprofiles where id = @user_profile_id FOR JSON PATH';
exports.SELECT_USER_PROFILES=
'select * FROM userprofiles FOR JSON PATH';
exports.DELETE_USER_PROFILE=
'UPDATE userprofiles SET Deleted = 1 WHERE id = @user_profile_id';

View File

@ -0,0 +1,33 @@
'use strict';
var Mockgen = require('./mockgen.js');
var queries = require('./queries');
/**
* Operations on /user
*/
module.exports = {
/**
* summary:
* description: List all user profiles
* parameters:
* produces:
* responses: 200, default
* operationId: getAllUsers
*/
get: {
200: function (req, res, callback) {
req.sql(queries.SELECT_USER_PROFILES)
.into(res);
callback;
},
default: function (req, res, callback) {
Mockgen().responses({
path: '/user',
operation: 'get',
response: 'default'
}, callback);
}
}
};

View File

@ -0,0 +1,149 @@
'use strict';
var Mockgen = require('../mockgen.js');
var TYPES = require('tedious').TYPES;
var queries = require('../queries');
/**
* Operations on /user/{userID}
*/
module.exports = {
/**
* summary:
* description: Get a User Profile by ID
* parameters:
* produces:
* responses: 200, default
* operationId: userGET
*/
get: {
200: function (req, res, callback) {
req.sql(queries.SELECT_USER_PROFILE_BY_ID)
.param('user_profile_id', req.params.userID, TYPES.NVarChar)
.into(res, '{}');
callback;
},
default: function (req, res, callback) {
/**
* Using mock data generator module.
* Replace this by factual data for the api.
*/
Mockgen().responses({
path: '/user/{userID}',
operation: 'get',
response: 'default'
}, callback);
}
},
/**
* summary:
* description: Declares and creates a new profile
* parameters: _profile
* produces:
* responses: 201, default
* operationId: userPOST
*/
post: {
201: function (req, res, callback) {
req.sql(queries.INSERT_USER_PROFILE)
.param('UserProfileJson', req.body, TYPES.NVarChar)
.exec(res);
callback;
},
default: function (req, res, callback) {
/**
* Using mock data generator module.
* Replace this by actual data for the api.
*/
Mockgen().responses({
path: '/user/{userID}',
operation: 'post',
response: 'default'
}, callback);
}
},
/**
* summary:
* description: Update User
* parameters:
* produces:
* responses: 200, 404, default
* operationId: updateUser
*/
patch: {
200: function (req, res, callback) {
req.sql('EXEC UpdateProductFromJson @id, @json')
.param('json', req.body, TYPES.NVarChar)
.param('id', req.params.id, TYPES.Int)
.exec(res);
callback;
},
404: function (req, res, callback) {
/**
* Using mock data generator module.
* Replace this by actual data for the api.
*/
Mockgen().responses({
path: '/user/{userID}',
operation: 'patch',
response: '404'
}, callback);
},
default: function (req, res, callback) {
/**
* Using mock data generator module.
* Replace this by actual data for the api.
*/
Mockgen().responses({
path: '/user/{userID}',
operation: 'patch',
response: 'default'
}, callback);
}
},
/**
* summary:
* description: Delete User By ID
* parameters:
* produces:
* responses: 204, 404, default
* operationId: userDELETE
*/
delete: {
204: function (req, res, callback) {
var tempmessage = '';
var resmessage = tempmessage.concat('User profile ',req.params.userID,' deleted');
req.sql(queries.DELETE_USER_PROFILE)
.param('user_profile_id', req.params.userID, TYPES.NVarChar)
.into(res, resmessage);
callback;
},
404: function (req, res, callback) {
/**
* Using mock data generator module.
* Replace this by actual data for the api.
*/
Mockgen().responses({
path: '/user/{userID}',
operation: 'delete',
response: '404'
}, callback);
},
default: function (req, res, callback) {
/**
* Using mock data generator module.
* Replace this by actual data for the api.
*/
Mockgen().responses({
path: '/user/{userID}',
operation: 'delete',
response: 'default'
}, callback);
}
}
};