diff --git a/package.json b/package.json index c0a733f..74deb85 100644 --- a/package.json +++ b/package.json @@ -6,10 +6,11 @@ "scripts": { "start": "npm run build && node ./lib/typegoose.js", "build": "rimraf lib && tsc", + "build:tests": "rimraf lib && cd src/test && tsc", "lint": "tslint --project tsconfig.json", "test": "npm run lint && npm run cover", - "mocha": "npm run build && mocha ./lib --recursive", - "cover": "npm run build && istanbul cover _mocha -- lib --recursive -R spec", + "mocha": "npm run build:tests && mocha ./lib --recursive", + "cover": "npm run build:tests && istanbul cover _mocha -- lib --recursive -R spec", "coveralls": "cat ./coverage/lcov.info | coveralls" }, "repository": { @@ -24,11 +25,11 @@ "lodash": "4.17.10" }, "peerDependencies": { + "@types/mongoose": "5.0.10", "mongoose": "^5.0.0", "reflect-metadata": "^0.1.8" }, "devDependencies": { - "@types/mongoose": "5.0.10", "@types/chai": "4.1.3", "@types/dotenv": "4.0.3", "@types/lodash": "4.14.108", diff --git a/src/prop.ts b/src/prop.ts index dd4ea32..475d578 100644 --- a/src/prop.ts +++ b/src/prop.ts @@ -23,6 +23,7 @@ export interface BasePropOptions { export interface PropOptions extends BasePropOptions { ref?: any; + refType?: any; } export interface ValidateNumberOptions { @@ -86,9 +87,13 @@ const baseProp = (rawOptions, Type, target, key, isArray = false) => { const ref = rawOptions.ref; if (ref) { + let refType = mongoose.Schema.Types.ObjectId; + if (rawOptions.refType) { + refType = rawOptions.refType; + } schema[name][key] = { ...schema[name][key], - type: mongoose.Schema.Types.ObjectId, + type: refType, ref: ref.name, }; return; @@ -96,9 +101,13 @@ const baseProp = (rawOptions, Type, target, key, isArray = false) => { const itemsRef = rawOptions.itemsRef; if (itemsRef) { + let refType = mongoose.Schema.Types.ObjectId; + if (rawOptions.refType) { + refType = rawOptions.refType; + } schema[name][key][0] = { ...schema[name][key][0], - type: mongoose.Schema.Types.ObjectId, + type: refType, ref: itemsRef.name, }; return; diff --git a/src/test/tsconfig.json b/src/test/tsconfig.json new file mode 100644 index 0000000..dfd9f03 --- /dev/null +++ b/src/test/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.json", + "include": [ + "../**/*.ts" + ], + "exclude": [ + + ] +} diff --git a/tsconfig.json b/tsconfig.json index c3aa0d4..5edff9b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,5 +11,8 @@ }, "include": [ "src/**/*.ts" + ], + "exclude": [ + "src/test/**/*.ts" ] }