chore: add eslint to functions

This commit is contained in:
Kyle Fang
2019-09-26 14:28:06 +08:00
parent f9df1fb867
commit acbe0ff6cc
6 changed files with 153 additions and 339 deletions

View File

@@ -6,8 +6,8 @@
"nohoist": []
},
"scripts": {
"lint": "tslint --project tsconfig.json",
"build": "tsc",
"lint": "eslint **/*.ts",
"ci": "yarn lint && yarn build",
"serve": "yarn build && firebase serve --only functions",
"shell": "yarn build && firebase functions:shell"
@@ -15,24 +15,14 @@
"main": "lib/index.js",
"dependencies": {
"@google-cloud/storage": "^2.5.0",
"busboy": "^0.3.1",
"cookie-parser": "^1.4.4",
"cors": "^2.8.5",
"express": "^4.17.1",
"firebase-admin": "^8.2.0",
"firebase-functions": "^3.0.1",
"image-size": "^0.7.4",
"pure-uuid": "^1.5.7",
"sharp": "^0.22.1"
"firebase-functions": "^3.0.1"
},
"devDependencies": {
"@types/busboy": "^0.2.3",
"@types/cookie-parser": "^1.4.1",
"@types/cors": "^2.8.5",
"@types/image-size": "^0.7.0",
"@types/sharp": "^0.22.2",
"tslint": "^5.18.0",
"tslint-config-prettier": "^1.18.0",
"@typescript-eslint/eslint-plugin": "^2.3.1",
"@typescript-eslint/parser": "^2.3.1",
"eslint": "^6.4.0",
"eslint-config-prettier": "^6.3.0",
"typescript": "^3.6.3"
},
"engines": {

View File

@@ -1,51 +0,0 @@
import * as functions from "firebase-functions";
import { HttpsError } from "firebase-functions/lib/providers/https";
import * as admin from "firebase-admin";
import { Conversation, Doc } from "./types";
export const getProfile = async (userId: string) => {
return (await admin
.firestore()
.collection("users")
.doc(userId)
.get()).data();
};
export const newChat = functions.https.onCall(
async (data, context): Promise<Doc<Conversation>> => {
if (context.auth == null) {
throw new HttpsError("unauthenticated", "User not logged in");
}
if (typeof data.target !== "string") {
throw new HttpsError("invalid-argument", "target need to be a string");
}
const conversationRef = admin.firestore().collection("conversations");
const duplicate = await conversationRef
.where(
"_duplicateLookup" as keyof Conversation,
"==",
[context.auth.uid, data.target].sort().join(",")
)
.get();
if (!duplicate.empty) {
return {
id: duplicate.docs[0].id,
doc: duplicate.docs[0].data() as any
};
}
const newConversation = await conversationRef.add({
userDetails: {
[context.auth.uid]: await getProfile(context.auth.uid),
[data.target]: await getProfile(data.target)
},
userIds: [context.auth.uid, data.target],
updatedAt: admin.firestore.FieldValue.serverTimestamp() as any,
_duplicateLookup: [context.auth.uid, data.target].sort().join(",")
} as Conversation);
return {
id: newConversation.id,
doc: (await newConversation.get()).data() as any
};
}
);

View File

@@ -1,3 +1 @@
import * as chat from "./chat";
export { chat };
export {};

View File

@@ -1,14 +0,0 @@
{
"defaultSeverity": "error",
"extends": ["tslint:recommended", "tslint-config-prettier"],
"jsRules": {},
"rules": {
"ordered-imports": false,
"member-ordering": false,
"jsx-no-lambda": false,
"object-literal-sort-keys": false,
"interface-name": false,
"no-console": false
},
"rulesDirectory": []
}