-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #119 from hicsail/analyticsmodel
analytics
- Loading branch information
Showing
2 changed files
with
60 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
'use strict'; | ||
const Joi = require('joi'); | ||
const Assert = require('assert'); | ||
const AnchorModel = require('../anchor/anchor-model'); | ||
|
||
class Analytic extends AnchorModel { | ||
|
||
static async create(event,name,data,userId) { | ||
|
||
|
||
Assert.ok(event, 'Missing event argument'); | ||
Assert.ok(name, 'Missing name argument'); | ||
Assert.ok(data, 'Missing data arugment'); | ||
Assert.ok(userId, 'Missing userId argument'); | ||
|
||
const document = new this({ | ||
event, | ||
name, | ||
data, | ||
userId, | ||
createdAt: new Date() | ||
|
||
}); | ||
|
||
const analytics = await this.insertOne(document); | ||
|
||
return analytics[0]; | ||
|
||
} | ||
} | ||
|
||
Analytic.collectionName = 'analytics'; | ||
|
||
Analytic.schema = Joi.object({ | ||
_id: Joi.object(), | ||
event: Joi.string(), | ||
name: Joi.string(), | ||
data: Joi.object(), | ||
userId: Joi.string(), | ||
createdAt: new Date() | ||
|
||
|
||
}); | ||
|
||
Analytic.payload = Joi.object({ | ||
event: Joi.string(), | ||
name: Joi.string(), | ||
data: Joi.object() | ||
}); | ||
|
||
Analytic.indexes = [ | ||
{ key: { event: 1 } }, | ||
{ key : { email: 1 } } | ||
]; | ||
|
||
module.exports = Analytic; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters