Skip to content

Commit 356ca19

Browse files
Missing Dist Folder Added
1 parent 77d52ce commit 356ca19

File tree

16 files changed

+414
-0
lines changed

16 files changed

+414
-0
lines changed

dist/context/LineCheck.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
"use strict";
2+
var __importDefault = (this && this.__importDefault) || function (mod) {
3+
return (mod && mod.__esModule) ? mod : { "default": mod };
4+
};
5+
Object.defineProperty(exports, "__esModule", { value: true });
6+
exports.getLineCheckContext = void 0;
7+
const line_intersect_1 = __importDefault(require("@turf/line-intersect"));
8+
const helpers_1 = require("@turf/helpers");
9+
let lineCheckContext = null;
10+
class LineCheck {
11+
_refLineString;
12+
_linesToCheck = [];
13+
constructor() { }
14+
checkLineIntersections() {
15+
const intersections = [];
16+
if (this._refLineString && this._linesToCheck.length > 0) {
17+
const refLine = (0, helpers_1.lineString)(this._refLineString.coordinates.map(coordinate => coordinate));
18+
this._linesToCheck.forEach((line, index) => {
19+
const lineToIntersect = (0, helpers_1.lineString)(line.coordinates.map(coordinate => coordinate));
20+
const intersection = (0, line_intersect_1.default)(refLine, lineToIntersect);
21+
const intersectionPoints = {
22+
line: `L${index + 1}`,
23+
intersections: [],
24+
};
25+
intersection.features.forEach(feature => {
26+
intersectionPoints.intersections.push(feature.geometry.coordinates);
27+
});
28+
intersections.push(intersectionPoints);
29+
});
30+
}
31+
return intersections;
32+
}
33+
getRefLineString() {
34+
return this._refLineString;
35+
}
36+
updateRefLineString(lineString) {
37+
this._refLineString = lineString;
38+
}
39+
updateLinesToCheck(lines) {
40+
this._linesToCheck = lines;
41+
}
42+
clearLineString() {
43+
this._refLineString = undefined;
44+
}
45+
}
46+
function getLineCheckContext() {
47+
if (!lineCheckContext) {
48+
lineCheckContext = new LineCheck();
49+
}
50+
return lineCheckContext;
51+
}
52+
exports.getLineCheckContext = getLineCheckContext;

dist/context/User.js

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.getUserContext = void 0;
4+
const bcrypt_1 = require("bcrypt");
5+
const jsonwebtoken_1 = require("jsonwebtoken");
6+
let userContext = null;
7+
class UserContext {
8+
_users = [];
9+
constructor() {
10+
this.createDefaultUser();
11+
}
12+
async login(username, password) {
13+
const user = this._users.find(user => user.username === username);
14+
if (!user) {
15+
return [
16+
404,
17+
{
18+
data: null,
19+
error: 'User does not exist'
20+
},
21+
];
22+
}
23+
const correctPassword = await (0, bcrypt_1.compare)(password, user.password);
24+
if (correctPassword) {
25+
return [
26+
200,
27+
{
28+
error: null,
29+
data: {
30+
accessToken: (0, jsonwebtoken_1.sign)({
31+
username: user.username,
32+
name: user.name
33+
}, process.env.JWT_SECRET, { expiresIn: '1h' })
34+
}
35+
}
36+
];
37+
}
38+
return [
39+
401,
40+
{
41+
error: 'Wrong password. Please try again.',
42+
data: null
43+
}
44+
];
45+
}
46+
async create(username, password, name = '') {
47+
const userExist = this._users.some(user => user.username === username);
48+
if (userExist) {
49+
return [
50+
409,
51+
{
52+
data: null,
53+
error: 'Username already exists'
54+
}
55+
];
56+
}
57+
if (password.length < 8) {
58+
return [
59+
400,
60+
{
61+
data: null,
62+
error: 'Password should be more than 8 characters'
63+
}
64+
];
65+
}
66+
const user = {
67+
username,
68+
password: await (0, bcrypt_1.hash)(password, 10),
69+
name
70+
};
71+
this._users.push(user);
72+
return [
73+
201,
74+
{
75+
data: null,
76+
error: null
77+
}
78+
];
79+
}
80+
async createDefaultUser() {
81+
const user = {
82+
username: 'turfadmin',
83+
password: await (0, bcrypt_1.hash)('turf_password', 10),
84+
name: 'TurfJS Admin'
85+
};
86+
this._users.push(user);
87+
}
88+
}
89+
function getUserContext() {
90+
if (!userContext) {
91+
userContext = new UserContext();
92+
}
93+
return userContext;
94+
}
95+
exports.getUserContext = getUserContext;

dist/context/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.UserContext = exports.LineCheckContext = void 0;
4+
const LineCheck_1 = require("./LineCheck");
5+
Object.defineProperty(exports, "LineCheckContext", { enumerable: true, get: function () { return LineCheck_1.getLineCheckContext; } });
6+
const User_1 = require("./User");
7+
Object.defineProperty(exports, "UserContext", { enumerable: true, get: function () { return User_1.getUserContext; } });
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.clearLineString = void 0;
4+
const context_1 = require("../../context");
5+
async function clearLineString(request, response) {
6+
const lineCheck = (0, context_1.LineCheckContext)();
7+
const lineString = lineCheck.getRefLineString();
8+
if (!lineString) {
9+
return response.status(404).json({
10+
data: null,
11+
error: 'A GeoJSON.LineString object has not been defined.'
12+
});
13+
}
14+
lineCheck.clearLineString();
15+
return response.status(200).json({
16+
data: null,
17+
error: null
18+
});
19+
}
20+
exports.clearLineString = clearLineString;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.feedLineString = void 0;
4+
const context_1 = require("../../context");
5+
async function feedLineString(request, response) {
6+
const lineCheck = (0, context_1.LineCheckContext)();
7+
const lineStringObject = request.body;
8+
if (lineStringObject.type !== 'LineString') {
9+
return response.status(400).json({
10+
data: null,
11+
error: 'A GeoJSON.LineString object is expected'
12+
});
13+
}
14+
if (!lineStringObject.coordinates) {
15+
return response.status(400).json({
16+
data: null,
17+
error: 'GeoJSON.LineString object must have coordinates field defined'
18+
});
19+
}
20+
if (lineStringObject.coordinates && lineStringObject.coordinates.length <= 0) {
21+
return response.status(400).json({
22+
data: null,
23+
error: 'GeoJSON.LineString object must have coordinates field populated'
24+
});
25+
}
26+
lineCheck.updateRefLineString(lineStringObject);
27+
return response.status(201).json({
28+
data: lineCheck.getRefLineString(),
29+
error: null
30+
});
31+
}
32+
exports.feedLineString = feedLineString;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.getIntersectionPoints = void 0;
4+
const context_1 = require("../../context");
5+
async function getIntersectionPoints(request, response) {
6+
const lineCheck = (0, context_1.LineCheckContext)();
7+
const lines = request.body;
8+
if (!lines.length) {
9+
return response.status(400).json({
10+
data: null,
11+
error: 'GeoJSON.LineString objects is expected'
12+
});
13+
}
14+
lineCheck.updateLinesToCheck(lines.map(line => line.line));
15+
const intersections = lineCheck.checkLineIntersections();
16+
return response.status(200).json({
17+
data: intersections,
18+
error: null
19+
});
20+
}
21+
exports.getIntersectionPoints = getIntersectionPoints;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.getLineString = void 0;
4+
const context_1 = require("../../context");
5+
async function getLineString(request, response) {
6+
const lineCheck = (0, context_1.LineCheckContext)();
7+
const lineString = lineCheck.getRefLineString();
8+
if (!lineString) {
9+
return response.status(404).json({
10+
data: null,
11+
error: 'A GeoJSON.LineString object has not been defined.'
12+
});
13+
}
14+
return response.status(200).json({
15+
data: lineCheck.getRefLineString(),
16+
error: null
17+
});
18+
}
19+
exports.getLineString = getLineString;

dist/controller/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.LoginUser = exports.CreateUser = exports.GetIntersectionPoints = exports.ClearLineString = exports.GetLineString = exports.FeedLineString = void 0;
4+
const FeedLinestring_1 = require("./geojson/FeedLinestring");
5+
Object.defineProperty(exports, "FeedLineString", { enumerable: true, get: function () { return FeedLinestring_1.feedLineString; } });
6+
const GetLineString_1 = require("./geojson/GetLineString");
7+
Object.defineProperty(exports, "GetLineString", { enumerable: true, get: function () { return GetLineString_1.getLineString; } });
8+
const ClearLineString_1 = require("./geojson/ClearLineString");
9+
Object.defineProperty(exports, "ClearLineString", { enumerable: true, get: function () { return ClearLineString_1.clearLineString; } });
10+
const GetIntersectionPoints_1 = require("./geojson/GetIntersectionPoints");
11+
Object.defineProperty(exports, "GetIntersectionPoints", { enumerable: true, get: function () { return GetIntersectionPoints_1.getIntersectionPoints; } });
12+
const CreateUser_1 = require("./user/CreateUser");
13+
Object.defineProperty(exports, "CreateUser", { enumerable: true, get: function () { return CreateUser_1.createUser; } });
14+
const LoginUser_1 = require("./user/LoginUser");
15+
Object.defineProperty(exports, "LoginUser", { enumerable: true, get: function () { return LoginUser_1.loginUser; } });

dist/controller/user/CreateUser.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.createUser = void 0;
4+
const context_1 = require("../../context");
5+
async function createUser(request, response) {
6+
const userContext = (0, context_1.UserContext)();
7+
const user = request.body;
8+
if (!user.username) {
9+
return response.status(400).json({
10+
data: null,
11+
error: 'Username is required'
12+
});
13+
}
14+
if (!user.password) {
15+
return response.status(400).json({
16+
data: null,
17+
error: 'Password is required'
18+
});
19+
}
20+
const createResponse = await userContext.create(user.username, user.password, user.name);
21+
if (createResponse[1].error) {
22+
return response.status(createResponse[0]).json(createResponse[1]);
23+
}
24+
return response.status(createResponse[0]).json(createResponse[1]);
25+
}
26+
exports.createUser = createUser;

dist/controller/user/LoginUser.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.loginUser = void 0;
4+
const context_1 = require("../../context");
5+
async function loginUser(request, response) {
6+
const userContext = (0, context_1.UserContext)();
7+
const { username, password } = request.body;
8+
if (!username) {
9+
return response.status(400).json({
10+
data: null,
11+
error: 'Username is required'
12+
});
13+
}
14+
if (!password) {
15+
return response.status(400).json({
16+
data: null,
17+
error: 'Password is required'
18+
});
19+
}
20+
const loginResponse = await userContext.login(username, password);
21+
if (loginResponse[1].error) {
22+
return response.status(loginResponse[0]).json(loginResponse[1]);
23+
}
24+
return response.status(loginResponse[0]).json(loginResponse[1]);
25+
}
26+
exports.loginUser = loginUser;

0 commit comments

Comments
 (0)