Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Bug fix" #48

Open
wants to merge 1 commit into
base: prod
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 0 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,58 +13,3 @@

## Contributing
All pull requests must be branched off of and then requested to merge into the [dev](https://github.com/danerwilliams/ruski/tree/dev) branch. We will periodically merge the dev branch into the main prod branch as releases.

## Configurations
### Environment Variables
Environment variables must either be set or included in .env file inside of the backend folder.
##### Backend
AWS access keys for S3 uploading:
Be sure to use `sudo -E` when running node on port 80 to pass environment variables to the root user.
`ACCESS_KEY_ID=******************`
`SECRET_ACCESS_KEY=****************************`

### Cron
Run `crontab -e` to edit your crontab and add the following line:
`11 23 * * * ~/ruski/backend/cronjob-script.py 1> ~/ruski/backend/yack-beer-totals.json`

### S3
##### Bucket policy
```
{
"Version": "2008-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::***********:user/username"
},
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::myBucket/*"
},
{
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::myBucket/*"
}
]
}
```

##### CORS policy
```
[
{
"AllowedHeaders": [
"*"
],
"AllowedMethods": [
"PUT"
],
"AllowedOrigins": [
"*"
],
"ExposeHeaders": []
}
]
```
5 changes: 3 additions & 2 deletions backend/cronjob-script.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ def main():
result['yacks'] = yaks
result['beers'] = beers

print(json.dumps(result))
with open('yack-beer-totals.json', 'w') as file:
json.dump(result, file)


if __name__ == '__main__':
main()
main()
52 changes: 26 additions & 26 deletions backend/graphql/objects.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { GraphQLObjectType, GraphQLString, GraphQLInt,
GraphQLID, GraphQLList } = require('graphql');
GraphQLID, GraphQLList} = require('graphql');
const { GraphQLDateTime } = require('graphql-iso-date');

const User = require('../models/user');
Expand All @@ -18,26 +18,26 @@ const EloType = new GraphQLObjectType({
});

const UserType = new GraphQLObjectType({
name: 'User',
name: 'User',
fields: () => ({
id: { type: GraphQLID },
handle: { type: GraphQLString },
name: { type: GraphQLString },
email: { type: GraphQLString },
elo: { type: GraphQLInt },
elo_history: {
elo_history: {
type: new GraphQLList(EloType),
resolve(parent, args) {
return Elo.find({ '_id': { $in: parent.elo_history_ids } });
resolve(parent, args){
return Elo.find({'_id': { $in: parent.elo_history_ids}});
}
},
friends: {
type: new GraphQLList(UserType),
resolve(parent, args) {
return User.find({ '_id': { $in: parent.friend_ids } });
resolve(parent, args){
return User.find({'_id': { $in: parent.friend_ids }});
}
},
profile_url: { type: GraphQLString }
profile_url: { type: GraphQLString}
})
});

Expand All @@ -47,12 +47,12 @@ const PlayerType = new GraphQLObjectType({
id: { type: GraphQLID },
cups: { type: GraphQLInt },
penalties: { type: GraphQLInt },
user: {
user: {
type: UserType,
resolve(parent, args) {
resolve(parent, args){
return User.findById(parent.user_id);
}
}
}
})
});

Expand All @@ -65,15 +65,15 @@ const CommentType = new GraphQLObjectType({
text: { type: GraphQLString },
likes: { type: GraphQLInt },
user: {
type: UserType,
resolve(parent, args) {
type: UserType,
resolve(parent, args){
return User.findById(parent.user_id);
}
},
liked_by: {
type: new GraphQLList(UserType),
resolve(parent, args) {
return User.find({ '_id': { $in: parent.liked_by_ids } });
type: UserType,
resolve(parent, args){
return User.find({'_id': {$in: parent.liked_by_ids}});
}
}
})
Expand All @@ -87,29 +87,29 @@ const GameType = new GraphQLObjectType({
updatedAt: { type: GraphQLDateTime },
location: { type: GraphQLString },
description: { type: GraphQLString },
likes: { type: GraphQLInt },
likes: { type: GraphQLInt },
winning_team: {
type: new GraphQLList(PlayerType),
resolve(parent, args) {
return Player.find({ '_id': { $in: parent.winning_team_player_ids } });
resolve(parent, args){
return Player.find({'_id': { $in: parent.winning_team_player_ids }});
}
},
losing_team: {
type: new GraphQLList(PlayerType),
resolve(parent, args) {
return Player.find({ '_id': { $in: parent.losing_team_player_ids } });
resolve(parent, args){
return Player.find({'_id': { $in: parent.losing_team_player_ids }});
}
},
comments: {
type: new GraphQLList(CommentType),
resolve(parent, args) {
return Comment.find({ '_id': { $in: parent.comment_ids } });
resolve(parent, args){
return Comment.find({'_id': { $in: parent.comment_ids }});
}
},
liked_by: {
type: new GraphQLList(UserType),
resolve(parent, args) {
return User.find({ '_id': { $in: parent.liked_by_ids } });
type: UserType,
resolve(parent, args){
return User.find({'_id': {$in: parent.liked_by_ids}});
}
}
})
Expand Down
68 changes: 6 additions & 62 deletions backend/graphql/schemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,6 @@ const RootQuery = new GraphQLObjectType({
return User.find({email: args.email});
}
},
userByHandle: {
type: new GraphQLList(UserType),
args: { handle: { type: GraphQLString} },
resolve(parent, args) {
return User.find({handle: args.handle});
}
},
users: {
type: new GraphQLList(UserType),
resolve(parent, args) {
Expand Down Expand Up @@ -403,7 +396,7 @@ const Mutation = new GraphQLObjectType({
return Game.findById(args.id)
.then(response => {
let new_liked_by_id = mongoose.Types.ObjectId(args.liked_by_id);
filtered = response.liked_by_ids.filter(function(el) { return el != args.liked_by_id});
response.liked_by_ids.push(new_liked_by_id);
return Game.findByIdAndUpdate(
args.id,
{
Expand All @@ -413,7 +406,7 @@ const Mutation = new GraphQLObjectType({
description: response.description,
comment_ids: response.comment_ids,
likes: response.likes - 1,
liked_by_ids: filtered
liked_by_ids: response.liked_by_ids
}
);
});
Expand Down Expand Up @@ -452,14 +445,14 @@ const Mutation = new GraphQLObjectType({
return Comment.findById(args.id)
.then(response => {
let new_liked_by_id = mongoose.Types.ObjectId(args.liked_by_id);
filtered = response.liked_by_ids.filter(function(el) { return el != args.liked_by_id});
response.liked_by_ids.push(new_liked_by_id);
return Comment.findByIdAndUpdate(
args.id,
{
text: response.text,
user_id: response.user_id,
likes: response.likes - 1,
liked_by_ids: filtered
liked_by_ids: response.liked_by_ids
}
);
});
Expand Down Expand Up @@ -560,30 +553,7 @@ const Mutation = new GraphQLObjectType({
});
}
},
modifyName: {
type: UserType,
args: {
id: {type: new GraphQLNonNull(GraphQLID)},
name: {type: new GraphQLNonNull(GraphQLString)}
},
resolve(parent, args){
return User.findById(args.id)
.then(response => {
return User.findByIdAndUpdate(
args.id,
{
handle: response.handle,
name: args.name,
email: response.email,
elo: response.elo,
elo_history_ids: response.elo_history_ids,
friend_ids: response.friend_ids
}
);
});
}
},
addCommentToGame: {
addComment: {
type: GameType,
args: {
id: {type: new GraphQLNonNull(GraphQLID)},
Expand All @@ -592,7 +562,7 @@ const Mutation = new GraphQLObjectType({
resolve(parent, args){
return Game.findById(args.id)
.then(response => {
let new_comment_id = mongoose.Types.ObjectId(args.comment_id);
let new_comment_id = mongoose.Types.ObjectId(args.friend_id);
response.comment_ids.push(new_comment_id);
return Game.findByIdAndUpdate(
args.id,
Expand All @@ -607,33 +577,7 @@ const Mutation = new GraphQLObjectType({
)
});
}
},
deleteCommentFromGame: {
type: GameType,
args: {
id: {type: new GraphQLNonNull(GraphQLID)},
comment_id: {type: new GraphQLNonNull(GraphQLID)}
},
resolve(parent, args){
return Game.findById(args.id)
.then(response => {
let new_comment_id = mongoose.Types.ObjectId(args.comment_id);
filtered = response.comment_ids.filter(function(el) { return el != args.comment_id});
return Game.findByIdAndUpdate(
args.id,
{
winning_team_player_ids: response.winning_team_player_ids,
losing_team_player_ids: response.losing_team_player_ids,
location: response.location,
description: response.description,
comment_ids: filtered,
likes: response.likes
}
)
});
}
}

}
});

Expand Down
8 changes: 2 additions & 6 deletions backend/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ connection.once("open", function () {
console.log("MongoDB database connection established successfully");
});

app.get("/", (req, res) => {
res.send('cum');
});

// api endpoint for getting beer and yak totals from yack-beer-totals.json
app.get("/get_yack_beer_totals", (req, res) => {
res.send(fs.readFileSync('./yack-beer-totals.json', 'utf8'));
Expand Down Expand Up @@ -83,7 +79,7 @@ app.get("/get_presigned_url_png/:user_id", (req, res) => {
success: true,
message: "AWS SDK S3 Pre-signed urls generated successfully.",
presigned_url: url,
cdn_access_url: `https://d26n5v24zcmg6e.cloudfront.net/${params.Key}`,
cdn_access_url: `https://d26n5v24zcmg6e.cloudfront.net/${params.Key}.png`,
});
}
});
Expand All @@ -99,5 +95,5 @@ app.use(
);

app.listen(4000, () => {
console.log("Running a GraphQL API server at http://localhost/graphql (port 80)");
console.log("Running a GraphQL API server at http://localhost:4000/graphql");
});
20 changes: 0 additions & 20 deletions frontend/ruski-app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions frontend/ruski-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
"@types/gapi.auth2": "0.0.54",
"apollo-angular": "^2.4.0",
"graphql": "^15.5.0",
"hammerjs": "^2.0.8",
"ngx-image-cropper": "^3.3.5",
"rxjs": "~6.6.0",
"tslib": "^2.0.0",
"zone.js": "~0.11.3"
Expand Down
3 changes: 1 addition & 2 deletions frontend/ruski-app/src/app/graphql.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import {NgModule} from '@angular/core';
import {APOLLO_OPTIONS} from 'apollo-angular';
import {ApolloClientOptions, InMemoryCache} from '@apollo/client/core';
import {HttpLink} from 'apollo-angular/http';
import {environment} from '../environments/environment';

const uri = environment.api + '/graphql'; // <-- add the URL of the GraphQL server here
const uri = 'http://localhost:4000/graphql'; // <-- add the URL of the GraphQL server here
export function createApollo(httpLink: HttpLink): ApolloClientOptions<any> {
return {
link: httpLink.create({uri}),
Expand Down
Loading