ソースを参照

Fix type issues for mongo service. Fix dependencies

Tatiana Inama 7 年 前
コミット
7b7f6a8b43
3 ファイル変更61 行追加56 行削除
  1. 49 48
      ktchn/package.json
  2. 8 8
      ktchn/src/mongo.ts
  3. 4 0
      recipes/package.json

+ 49 - 48
ktchn/package.json

@@ -1,48 +1,49 @@
-{
-  "name": "ktchn",
-  "version": "0.0.0",
-  "private": true,
-  "scripts": {
-    "start": "ts-node --inspect-brk=9229 src/server.ts",
-    "dev": "node node_modules/nodemon/bin/nodemon.js ts-node --inspect-brk=9229 src/server.ts",
-    "build": "tsc -p .",
-    "build:live": "nodemon --watch 'src/**/*.ts' --exec ts-node src/server.ts"
-  },
-  "dependencies": {
-    "@types/chai": "^4.1.7",
-    "@types/cheerio": "^0.22.9",
-    "@types/cookie-parser": "^1.4.1",
-    "@types/dotenv": "^6.1.1",
-    "@types/express": "^4.16.0",
-    "@types/jest": "^23.3.12",
-    "@types/mongodb": "^3.1.19",
-    "@types/natural": "^0.2.33",
-    "@types/request": "^2.48.0",
-    "@types/request-promise": "^4.1.42",
-    "chai": "^4.2.0",
-    "cheerio": "^1.0.0-rc.2",
-    "cookie-parser": "~1.4.3",
-    "debug": "~2.6.9",
-    "dotenv": "^6.2.0",
-    "express": "~4.16.0",
-    "mongodb": "^3.1.13",
-    "morgan": "~1.9.0",
-    "nano": "^7.1.0",
-    "natural": "^0.6.3",
-    "ramda": "^0.26.1",
-    "recipe-ingredient-parser": "git+https://github.com/DavidVentura/recipe-parser.git",
-    "request": "^2.88.0",
-    "request-promise": "^4.2.4"
-  },
-  "devDependencies": {
-    "@types/morgan": "^1.7.35",
-    "@types/node": "^10.12.0",
-    "@types/ramda": "github:types/npm-ramda#dist",
-    "eslint": "^5.8.0",
-    "eslint-config-airbnb-base": "^13.1.0",
-    "eslint-plugin-import": "^2.14.0",
-    "nodemon": "^1.18.9",
-    "ts-node": "^7.0.1",
-    "typescript": "^3.3.3"
-  }
-}
+{
+  "name": "ktchn",
+  "version": "0.0.0",
+  "private": true,
+  "scripts": {
+    "start": "ts-node --inspect-brk=9229 src/server.ts",
+    "dev": "node node_modules/nodemon/bin/nodemon.js ts-node --inspect-brk=9229 src/server.ts",
+    "build": "tsc -p .",
+    "build:live": "nodemon --watch 'src/**/*.ts' --exec ts-node src/server.ts"
+  },
+  "dependencies": {
+    "@types/chai": "^4.1.7",
+    "@types/cheerio": "^0.22.9",
+    "@types/cookie-parser": "^1.4.1",
+    "@types/dotenv": "^6.1.1",
+    "@types/express": "^4.16.0",
+    "@types/jest": "^23.3.12",
+    "@types/mongodb": "^3.1.19",
+    "@types/natural": "^0.2.33",
+    "@types/request": "^2.48.0",
+    "@types/request-promise": "^4.1.42",
+    "chai": "^4.2.0",
+    "cheerio": "^1.0.0-rc.2",
+    "cookie-parser": "~1.4.3",
+    "debug": "~2.6.9",
+    "dotenv": "^6.2.0",
+    "express": "~4.16.0",
+    "moment": "^2.24.0",
+    "mongodb": "^3.1.13",
+    "morgan": "~1.9.0",
+    "nano": "^7.1.0",
+    "natural": "^0.6.3",
+    "ramda": "^0.26.1",
+    "recipe-ingredient-parser": "git+https://github.com/DavidVentura/recipe-parser.git",
+    "request": "^2.88.0",
+    "request-promise": "^4.2.4"
+  },
+  "devDependencies": {
+    "@types/morgan": "^1.7.35",
+    "@types/node": "^10.12.0",
+    "@types/ramda": "github:types/npm-ramda#dist",
+    "eslint": "^5.8.0",
+    "eslint-config-airbnb-base": "^13.1.0",
+    "eslint-plugin-import": "^2.14.0",
+    "nodemon": "^1.18.9",
+    "ts-node": "^7.0.1",
+    "typescript": "^3.3.3"
+  }
+}

+ 8 - 8
ktchn/src/mongo.ts

@@ -1,4 +1,4 @@
-import { Db, Cursor, MongoClient, InsertOneWriteOpResult, Collection, ObjectID, FilterQuery, ObjectId, UpdateWriteOpResult, WriteOpResult, CollectionAggregationOptions, AggregationCursorResult } from 'mongodb';
+import { Db, Collection, ObjectID, FilterQuery, ObjectId, WriteOpResult, FindOneOptions } from 'mongodb';
 
 export interface IDDocument {
   _id: ObjectID
@@ -11,7 +11,7 @@ export interface IMongoService {
   insertMany<T>(data: T[]): Promise<IDBDocument<T>[]|any[]>,
   findOne<T>(query: FilterQuery<T>): Promise<IDBDocument<T>|null>,
   findOneById<T>(idParam: string): Promise<IDBDocument<T>|null>,
-  find<T>(query: FilterQuery<T>, optionalQuery?: FilterQuery<T>): Promise<IDBDocument<T>[]>,
+  find<T>(query: FilterQuery<T>, optionalQuery?: FindOneOptions): Promise<IDBDocument<T>[]>,
   update<T>(id: string, data: T): Promise<WriteOpResult>,
   aggregate<T>(pipeline: Object[]): Promise<T[]>
 }
@@ -20,13 +20,13 @@ export const mongoService = (db: Db) => (col: string): IMongoService => {
   const collection: Collection = db.collection(col);
 
   return {
-    insertOne: <T>(data: T): Promise<IDBDocument<T>> => collection.insertOne(data).then(insertOneResult => insertOneResult.ops[0]),
-    insertMany: <T>(data: T[]): Promise<any[]|IDBDocument<T>[]> => collection.insertMany(data).then(insertManyResult => insertManyResult.ops),
-    findOne: <T>(query: FilterQuery<T>) => collection.findOne(query),
+    insertOne: data => collection.insertOne(data).then(insertOneResult => insertOneResult.ops[0]),
+    insertMany: data => collection.insertMany(data).then(insertManyResult => insertManyResult.ops),
+    findOne: query => collection.findOne(query),
     findOneById: (idParam: string) => collection.findOne({ _id: new ObjectId(idParam) }),
-    find: <T>(query: FilterQuery<T>, optionalQuery: FilterQuery<T> = {} ): Promise<IDBDocument<T>[]> => collection.find(query, optionalQuery).toArray(),
-    update: <T>(id: string, data: T) => collection.update({_id: new ObjectId(id)}, data),
-    aggregate: <T>(pipeline: Object[]) => collection.aggregate<T>(pipeline).toArray()
+    find: (query, optionalQuery) => collection.find(query, optionalQuery).toArray(),
+    update: (id, data) => collection.update({_id: new ObjectId(id)}, data),
+    aggregate: pipeline => collection.aggregate(pipeline).toArray()
   }
 };
 

+ 4 - 0
recipes/package.json

@@ -6,6 +6,7 @@
     "@material/react-button": "^0.11.0",
     "@material/react-card": "^0.11.0",
     "@material/react-chips": "^0.12.0",
+    "@material/react-dialog": "^0.15.0",
     "@material/react-drawer": "^0.11.0",
     "@material/react-icon-button": "^0.12.0",
     "@material/react-layout-grid": "^0.11.0",
@@ -17,8 +18,10 @@
     "@material/react-tab-indicator": "^0.13.0",
     "@material/react-text-field": "^0.11.0",
     "@material/ripple": "^2.3.0",
+    "@types/classnames": "^2.2.9",
     "@types/jest": "^24.0.15",
     "@types/node": "^11.13.17",
+    "@types/ramda": "^0.26.22",
     "@types/react": "^16.8.23",
     "@types/react-beautiful-dnd": "^11.0.3",
     "@types/react-dom": "^16.8.3",
@@ -26,6 +29,7 @@
     "@types/storybook__addon-actions": "^3.4.3",
     "@types/storybook__addon-links": "^3.3.5",
     "@types/storybook__react": "^4.0.2",
+    "@types/throttle-debounce": "^2.1.0",
     "axios": "^0.19.0",
     "classnames": "^2.2.6",
     "convert-units": "git+https://github.com/ben-ng/convert-units.git",