eddiehubcommunity / api Goto Github PK
View Code? Open in Web Editor NEWAPI to manage our community data
Home Page: https://api.eddiehub.io
License: MIT License
API to manage our community data
Home Page: https://api.eddiehub.io
License: MIT License
Automated testing end-to-end with what NestJS recommend (remove unit testing)
Subtask of #12
When removing a Discorduser the Check for Not-Found-Exception isnt working as intended
remove(id: number) {
const updatedDiscord = this.discord.filter((user) => user.id !== id);
//this checks if an Array is undefined, not if the Element to delete is present
if (!updatedDiscord) {
throw new HttpException('User Not Found', HttpStatus.NOT_FOUND);
}
this.discord = [...updatedDiscord];
return 'User deleted successfully!';
}
We should add github actions here.
It could be similar to EddieBot.
I would like to do this but it would be my first time and I have to learn it first and practice on one of my repos.
If you wouldn't mind I could do it in 2 or 3 days.
We should use helmet to improve security for our api.
Its like a default-package when building an api with express.
Helmet
Location will come from GitHub data, no need for the user to set it via the Discord Bot
This issue is a subtask of #12
Discord
interface Discord {
uid: string;
location: {
text: string;
lat: number;
lng: number;
};
socials: {
[key: string]: string; // GitHub, linkedin, instagram, twitter
}
}
Nest provides the opportunity to use Validationpipe using class-validator
and class-transformer
.
Maybe we should think about using this pipe fot Data-Transfer-Objects.
Feel free to discuss on this topic.
We should add some documentation for setting up mongo for running this locally, related to the project, of course.
We should also add a link to the MongoDB official page for more instructions.
Share your opinion about this.
The Unittests which are currently available are the predefined ones. Should we invest time in Unittests in addition to e2e-tests?
Event totals are already saved, but would also be good to store the event with the date in another collection (could have a ttl)
Conversation from here EddieHubCommunity/EddieBot#476
Save event totals in existing Discord user document, but would also be good to store the event with the date in another collection (could have a ttl)
Example in http://github.com/eddiejaoude/stargate
Discussed here #76 (comment)
I think we need to create another step def similar to this one that would make it easier to read - I can do it in another PR after this one is merged.
@then(/the response in item "([^"]*)" should contains:/)
public dataResponseItemTable(item: number, table: { rawTable: [] }) {
const data = this.context.tableToObject(table);
expect(JSON.parse(this.context.response.text)[item]).to.to.eql(data);
}
https://github.com/EddieHubCommunity/api/blob/main/test/step-definitions/responses.ts#L31
The new step def would be something like this
@then(/the response property "([^"]*)" in field "([^"]*)" should contains:/)
public dataResponseItemTable(property: string, item: number, table: { rawTable: [] }) {
const data = this.context.tableToObject(table);
expect(JSON.parse(this.context.response.text)[property][item]).to.eql(data);
}
The tests would be something like
And the response property "future" in item "0" should contains:
| id | 123 |
| name | "Livestream XY" |
And the response property "ongoing" in item "0" should contains:
| id | 123 |
| name | "Livestream YZ" |
Note: I think contains
should be singular ๐ค - this can be changed later
To document our API, using Swagger and the OpenAPI specification will benefit us since it's a known standard in the industry. I don't think we'll have a hypermedia API, so there is no need to worry about documenting the URLs.
We can have a look at this: https://github.com/feathersjs-ecosystem/feathers-swagger.
Let me know what other suggestions you have for documentation and what you think ๐
GitHub
interface GitHub {
username: string;
bio: string; // do we need Discord bio?
avatarUrl: string
followers: number;
repos: number;
// ... any other useful info public info https://docs.github.com/en/rest/reference/users
communityStats: {
[key: string]: number
};
}
Also playing with #61
There has been some discussion about the technology choices for this project here: #1. So I was thinking we could get the project started and continue from there ๐.
The goal of this issue would be to bootstrap the project and get most stuff setup. So here are the tasks I purpose we complete:
The API crashes when no real Data is returned from the geocoding-Service.
I suggest adding try-catch
adding to it.
When code is changed, the tests still pass
Make sure to use v5
To just transfer deltas when changing data, we should introduce Patch-Endpoints
The actual Database needs to be connected to our API
In discord-service after changing the values in existing Userobject coming from the DTO arent updated in discord
-Array.
update(id: number, updateDiscordDto: UpdateDiscordDto) {
const { username, bio, socials } = updateDiscordDto;
const discordUser = this.discord.find((user) => user.id === id);
if (!discordUser) {
throw new HttpException('User Not Found', HttpStatus.NOT_FOUND);
}
const updatedDiscord = { ...discordUser };
if (username) {
updatedDiscord.username = username;
}
if (bio) {
updatedDiscord.bio = bio;
}
if (socials && socials.discord) {
updatedDiscord.socials.discord = socials.discord;
}
if (socials && socials.twitter) {
updatedDiscord.socials.twitter = socials.twitter;
}
if (socials && socials.linkedin) {
updatedDiscord.socials.linkedin = socials.linkedin;
}
if (socials && socials.github) {
updatedDiscord.socials.github = socials.github;
}
//existing discordUser needs to be updated here before returning string
return 'User updated successfully!';
}
Make some changes in the discord
resource.
interface Member {
username: string;
bio: string,
socials: {
discord: string
twitter: string;
linkedin: string;
github: string;
};
updatedOn: Date;
createdOn: Date;
}
When growing the Application we might need some Monitoring about Performance, Failures or Errors. We could potentially implement centralized logging to Azure App Insights or Sentry.
If we do so, we could also implement this to the different Frontends like EddieBot or a Website
Currently, the data is managed (CRUD) in Memory.
It needs to be replaced with typeorm
using MongoDB
This is a subtask (#12)
interface Member {
username: string;
bio: {
description: string;
twitter: string;
linkedin: string;
github: string;
};
updatedOn: Date;
createdOn: Date;
}
Do we need rate-limiting for the api, that we cant get ddosed?
We could set how many requests in a specific interval are served directly, while the additional ones are delayed automatically.
When doing asynchronous operations (http-calls, access database) within our code, we should spike if Promises or Observables work better for us.
Document how to write the automated tests and the different styles, here is an example
Scenario: get list of events
Given make a GET request to "/calendar"
Then the response status code should be 200
And the response should contain:
| future | [] |
| ongoing | [] |
We could think about using a Rest-Api-Design-Guideline like this for designing out endpoints consistently
This issue is a subtask of #12
The job is to create a basic api
boilerplate using NestJS CLI
Does this Api need to be protected by JWT using passport
for example?
In case of having a "Community Calendar" we could integrate this to the Api, to access Data from that Calendar in other projects as well.
Before realizing that we should definitly specify some more Details - Feel free to Add Ideas in the Comments!
api
project from CLIdiscord
with the generate command resource
docsmember
without DBinterface Member {
username: string;
bio: string;
socials: {
discord: string;
twitter: string;
linkedin: string;
github: string;
};
updatedOn: Date;
createdOn: Date;
}
typeorm
docsNotes for the future
It would be great to encourage more daily standup information.
Update after discussion with @mstanciu552 below
send the information from EddieBot to the API using axios or fetch and then save them in a users collection in our db
https://github.com/eddiejaoude/stargate/blob/main/.github/workflows/labels.yml
Copy the content and create it with the same path
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.