Skip to content

Commit

Permalink
Removing i18next and Redux.
Browse files Browse the repository at this point in the history
  • Loading branch information
BenjaVR committed Dec 24, 2018
1 parent 8aa1021 commit 023cb0b
Show file tree
Hide file tree
Showing 38 changed files with 632 additions and 1,437 deletions.
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"files.associations": {
".firebaserc": "jsonc"
}
},
"npm.packageManager": "yarn",
"typescript.tsdk": "node_modules\\typescript\\lib"
}
3 changes: 1 addition & 2 deletions firestore.rules
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read: if request.auth.uid != null;
allow write: if false;
allow read, write: if exists(/databases/$(database)/documents/users/$(request.auth.uid));
}
}
}
44 changes: 22 additions & 22 deletions functions/package.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
{
"name": "@studentplanner/functions",
"version": "1.0.0",
"scripts": {
"lint": "tslint --project tsconfig.json",
"build": "tsc --skipLibCheck",
"build:watch": "tsc -w --skipLibCheck",
"serve": "npm run build && firebase serve --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"main": "dist/index.js",
"dependencies": {
"firebase-admin": "~6.0.0",
"firebase-functions": "^2.1.0"
},
"devDependencies": {
"tslint": "~5.8.0",
"typescript": "~2.8.3"
},
"private": true
"name": "studentplanner-functions",
"version": "1.0.0",
"private": true,
"scripts": {
"lint": "tslint --project tsconfig.json",
"build": "tsc",
"build:watch": "tsc -w",
"serve": "npm run build && firebase serve --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"main": "dist/index.js",
"dependencies": {
"firebase-admin": "6.4.0",
"firebase-functions": "2.1.0"
},
"devDependencies": {
"tslint": "5.12.0",
"typescript": "3.2.2"
}
}
53 changes: 1 addition & 52 deletions functions/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,63 +1,12 @@
import * as admin from "firebase-admin";
import * as functions from "firebase-functions";
import { UserRecord } from "firebase-functions/lib/providers/auth";
import { CallableContext, HttpsError } from "firebase-functions/lib/providers/https";
import { schoolsCollection } from "./shared/firebase/firestoreConstants";
import { IFirebaseFunctionParam as Param } from "./shared/firebase/interfaces";
import { ISchool, validateSchool } from "./shared/models/School";

admin.initializeApp();
const db = admin.firestore();
const auth = admin.auth();

///////////////
// Utilities //
///////////////

function checkAuthentication(context: CallableContext): void {
if (!context.auth) {
throw new HttpsError("unauthenticated", "You need permissions"); // TODO: translate
}
}

function errorCallback(details: any): void {
throw new HttpsError("unknown", "Something went wrong... Please try again later!", details); // TODO: translate
}

/////////////////////////
// Database operations //
/////////////////////////

export const addSchool = functions.https.onCall((param: Param<ISchool>, context): Promise<ISchool> => {
checkAuthentication(context);

return new Promise<ISchool>(((resolve) => {
const validated = validateSchool(param.data);
if (validated.hasErrors()) {
throw new HttpsError("invalid-argument", "Fields are not correct", validated); // TODO: translate
} else {
db.collection(schoolsCollection).add(param.data)
.then((ref) => {
return ref.get();
})
.then((doc) => {
const school = {
...doc.data(),
id: doc.id,
};
resolve(school as ISchool);
})
.catch(errorCallback);
}
}));
});

/////////////////////////////
// Authentication triggers //
/////////////////////////////

/**
* Disables users after they sign up. This prevents random people somehow succeeded to sign up from logging in.
* Disables users after they sign up. This prevents random people (somehow succeeded to sign up) from logging in.
*/
export const disableUserAfterSignUp = functions.auth.user().onCreate((user: UserRecord): void => {
auth.updateUser(user.uid, {
Expand Down
1 change: 0 additions & 1 deletion functions/src/shared/.gitignore

This file was deleted.

1 change: 0 additions & 1 deletion functions/src/shared/firebase/firestoreConstants.ts

This file was deleted.

6 changes: 0 additions & 6 deletions functions/src/shared/firebase/interfaces.ts

This file was deleted.

28 changes: 0 additions & 28 deletions functions/src/shared/models/LoginDetails.ts

This file was deleted.

29 changes: 0 additions & 29 deletions functions/src/shared/models/School.ts

This file was deleted.

15 changes: 0 additions & 15 deletions functions/src/shared/translations/En.ts

This file was deleted.

15 changes: 0 additions & 15 deletions functions/src/shared/translations/Nl.ts

This file was deleted.

21 changes: 0 additions & 21 deletions functions/src/shared/translations/types.ts

This file was deleted.

5 changes: 0 additions & 5 deletions functions/src/shared/validators/FirebaseValidator.ts

This file was deleted.

6 changes: 0 additions & 6 deletions functions/src/shared/validators/StringValidator.ts

This file was deleted.

15 changes: 0 additions & 15 deletions functions/src/shared/validators/ValidationError.ts

This file was deleted.

23 changes: 0 additions & 23 deletions functions/src/shared/validators/ValidationResult.ts

This file was deleted.

44 changes: 23 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
{
"name": "studentplanner",
"private": true,
"version": "1.0.0",
"scripts": {
"build-web": "npm --prefix web run start",
"build-functions": "npm --prefix functions run build:watch",
"build": "npm-run-all --continue-on-error --parallel build-functions build-web"
},
"repository": "git+https://github.com/BenjaVR/StudentPlanner.git",
"author": "Benjamin Van Renterghem",
"license": "ISC",
"bugs": {
"url": "https://github.com/BenjaVR/StudentPlanner/issues"
},
"homepage": "https://github.com/BenjaVR/StudentPlanner#readme",
"devDependencies": {
"npm-run-all": "^4.1.5"
},
"workspaces": [
"functions", "web"
]
"name": "studentplanner",
"private": true,
"version": "1.0.0",
"scripts": {
"build-web": "npm --prefix web run start",
"build-functions": "npm --prefix functions run build:watch",
"build": "npm-run-all --continue-on-error --parallel build-functions build-web",
"deploy": "firebase deploy"
},
"repository": "git+https://github.com/BenjaVR/StudentPlanner.git",
"author": "Benjamin Van Renterghem",
"license": "ISC",
"bugs": {
"url": "https://github.com/BenjaVR/StudentPlanner/issues"
},
"homepage": "https://github.com/BenjaVR/StudentPlanner#readme",
"devDependencies": {
"npm-run-all": "4.1.5"
},
"workspaces": [
"web",
"functions"
]
}
Loading

0 comments on commit 023cb0b

Please sign in to comment.