my-agile-story-api is a Node.js RESTful web service that is used by my-agile-story-web. It connects to a mongoDB database provisioned on mongoDB atlas.
my-agile-story-api uses the following three data schemas: developer, project and userStory.
var developerSchema = new Schema({
firstName: String,
lastName: String,
email: String,
password: String,
bio: String,
role: String,
projectIds: [{ type: ObjectId, ref: "Project" }],
timeStampISO: String
});
var projectSchema = new Schema({
name: String,
description: String,
developerIds: [{ type: ObjectId, ref: "Developer" }],
userStoryIds: [{ type: ObjectId, ref: "UserStory" }],
timeStampISO: String
});
var userStorySchema = new Schema({
userStoryTitle: String,
userRole: String,
userWant: String,
userBenefit: String,
acceptanceCriteria: String,
conversation: String,
estimate: Number,
phase: String,
percentDone: Number,
priority: Number,
sprint: Number,
projectId: { type: ObjectId, ref: "Project" },
timeStampISO: String
});
GET, PUT, and DELETE do not allow you to send a JSON body. Some calls might have data that is longer than the 2000 character limitation of GET, PUT and DELETE. For example if you want to delete many records by Id. You can simply use JSON.stringify
while creating a JSON body which is not limited to 2000 characters.
Also these methods can be logged on both the server and the client. This is undesirable for security reasons. Therefore we will be using POST for most methods.
We recommend calling the REST methods with fetch which returns a promise. For example a typical post request would be as follows.
var myDeveloper = {};
var errMessage = "";
fetch(URL_Address + "/developer", {
method: "post",
headers: {
Accept: "application/json, text/plain, */*",
"Content-Type": "application/json"
},
body: JSON.stringify({
email: email,
password: password,
firstName: firstName,
lastName: lastName,
bio: bio,
role: role
})
})
.then(res =>
res.json().then(data => ({
status: res.status,
body: data
}))
)
.then(obj => {
if (obj.status === 200) {
myDeveloper = obj.body;
errMessage = "No Error";
//do stuff with myDeveloper
} else {
errMessage = "Error" + obj.body.error;
//do stuff with errMessage
}
});
To create a new developer use POST /developer
with a JSON body consisting of key value pairs: email, password, firstName, lastName, bio and role. ProjectIds are not passed. ProjectIds will be assigned later when the new developer creates a new project or is added to an existing project.
To create a new project use POST /project
with a JSON body consisting of key value pairs: name, description.
To create a new user story use POST /project/userStory
with a JSON body consisting of key value pairs: userStoryTitle, userRole, userWant, userBenifit, acceptanceCriteria, conversation, estimate, phase, percentDone, priority, sprint, projectId.
To get a developer use POST /get/developer
with a JSON body consisting of key value pairs: email, password.
To get a project use POST /get/project
with a JSON body consisting of key value pair: projectId. This is the endpoint that is used to check if the project changed buy comparing the timeStampISO to the one on the client side.
To get an array of projects use POST /get/projects
with a JSON body consisting of key value pair: projectIds. ProjectIds is a an array of projectId.
To get a user story use POST /get/userStory
with a JSON body consisting of key value pair: projectId.
To get an array of user stories use POST /get/userStorys
with a JSON body consisting of key value pair: userStoryIds. userStoryIds is an array of userStoryId.
To delete a developer uses POST /delete/developer
with a JSON body consisting of key value pair: developerId.
To delete a developer from a project use POST /delete/developer/project
with a JSON body consisting of key value pairs: developerId, projectId.
To delete a user story from a project use POST /delete/project/userStory
with a JSON body consisting of key value pairs: userStoryId, projectId.
To delete many user stories from a project use POST /delete/project/userStory
with a JSON body consisting of key value pairs: userStoryIds, projectId. userStoryIds is an array of userStoryId.
To edit a developer use POST /put/developer
with a JSON body consisting of key value pairs: developerId, firstName, lastName, bio, and role. ProjectIds are not passed they will remain the same.
To edit a project use POST /put/project
with a JSON body consisting of key value pairs: name, description.
To create a new user story use POST /put/userStory
with a JSON body consisting of key value pairs: userStoryTitle, userRole, userWant, userBenifit, acceptanceCriteria, conversation, estimate, phase, percentDone, priority, sprint. ProjectId is not passed because it does not change.