Skip to content

Commit f560f70

Browse files
authored
Merge pull request #31 from oslabs-beta/steve/object-type
Steve/object type
2 parents 7b732c2 + e680161 commit f560f70

File tree

7 files changed

+1428
-61
lines changed

7 files changed

+1428
-61
lines changed

lib/dango.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import {
1515
SchemaString, SchemaBoolean,
1616
SchemaObjectId,
1717
SchemaUUID,
18-
SchemaDate
18+
SchemaDate,
19+
SchemaObject,
1920
} from './datatypes.ts'
2021

2122
/**
@@ -39,6 +40,7 @@ class Dango {
3940
objectid: SchemaObjectId,
4041
UUID: SchemaUUID,
4142
date: SchemaDate,
43+
object: SchemaObject,
4244
}
4345
}
4446

lib/dango_test.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,20 @@ const dangoModel = dango.model('new', dangoSchema);
3737
// console.log(await dangoModel.insertOne({username: 'dango rules'}))
3838
// console.log(await dangoModel.findOne({ username: "dango rules" }));
3939
// console.log(await dangoModel.deleteOne({ username: "dango rules"}, (input) => {console.log('callback executed', input)}));
40-
// console.log(await dangoModel.updateMany({ name: 'Joker'}, { food: 'steak' }));
41-
console.log(await dangoModel.find({name: 'Joker' }));
40+
// console.log(await dangoModel.updateMany({ name: 'Joker'}, { food: 'dango' }));
41+
// console.log(await dangoModel.find({name: 'Joker' }));
4242
// console.log(await dangoModel.findByIdAndUpdate('62733a0b76beb44c3c17e674', { age: 'Merlin'}))
4343
// console.log(await dangoModel.findOneAndReplace({ name: 'Merlin' }, { name: 'Merlin', age: 100, food: 'starbursts'}));
4444
// console.log(await dangoModel.find({name: 'Merlin' }));
4545
// console.log(await dangoModel.findOneAndUpdate({ name: "Banantha" }, { food: "babies"}, (input) => {console.log('callback executed', input)}));
4646
// console.log(await dangoModel.find({ username: "jack" }));
4747
// console.log(await dangoModel.find());
4848
// console.log(await dangoModel.find({ username: 'test'}, { limit: 2 }));
49-
// console.log(await dangoModel.insertMany([ { name: 'Goose', age: 25 }, { name: 'Maverick', age: 26 } ]));
50-
// console.log(await dangoModel.findOne({ name: "Goose" }));
51-
// console.log(await dangoModel.findOne({ name: "Maverick" }));
49+
// console.log(await dangoModel.insertMany([ { name: 'Viper' }, { name: 'Slider', age: 26 } ]));
50+
// console.log(await dangoModel.findOne({ name: "Viper" }));
51+
// console.log(await dangoModel.findOne({ name: "Slider" }));
52+
// console.log(await dangoModel.countDocuments({ name: 'Carp'}));
53+
console.log(await dangoModel.estimatedDocumentCount());
5254

5355
// Test if we can bring connection into query specifically
5456
// Test queries from model

lib/datatypes.ts

+48
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,54 @@ export class SchemaDate {
432432
return this.convertedValue;
433433
}
434434

435+
/**
436+
* Checks whether the value was casted to the correct data type..
437+
* Sets valid property to true or false.
438+
*/
439+
validateType() {
440+
this.valid = this.convertedValue === undefined ? false : true;
441+
return this.valid;
442+
}
443+
}
444+
445+
// SCHEMA OBJ
446+
447+
export class SchemaObject {
448+
449+
public value: any;
450+
public valid: boolean | undefined;
451+
public convertedValue: Record<string, unknown> | null | undefined;
452+
453+
constructor(value: any) {
454+
if (value === undefined) {
455+
throw new Error('A value is required.')
456+
}
457+
this.value = value;
458+
this.convertedValue;
459+
this.valid
460+
}
461+
462+
/**
463+
* Attempts to convert raw value to the given data type.
464+
* Sets convertedValue property to the casted input if possible, or undefined if not.
465+
*/
466+
convertType() {
467+
if (this.value === null) {
468+
this.convertedValue = this.value;
469+
}
470+
471+
else if (typeof this.value === 'object') {
472+
this.convertedValue = this.value;
473+
// }
474+
}
475+
476+
else if (typeof this.value !== 'object') {
477+
return;
478+
}
479+
480+
return this.convertedValue;
481+
}
482+
435483
/**
436484
* Checks whether the value was casted to the correct data type..
437485
* Sets valid property to true or false.

0 commit comments

Comments
 (0)