Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions gqschema/analytic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = `
extend type Query {
events: customArray
}
extend type Mutation {
addLog(
IP: String!
customerId: ID
event: String!
from: String
data: customObject
): statusSchema
}
`;
36 changes: 36 additions & 0 deletions models/Analytic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const mongoose = require("mongoose")
const Schema = mongoose.Schema;

const eventValues = []
const fromValues = []

const AnalyticSchema = new Schema({
IP: {
type: String,
required: true
},
customerId: {
type: Schema.Types.ObjectId,
ref: "Customer"
},
event: {
type: String,
enum: eventValues,
required: true
},
from: {
type: String,
enum: fromValues
},
data: {},
date: {
type: Date,
default: Date.now()
}
})

module.exports = {
Analytic: mongoose.model('Analytics', AnalyticSchema),
eventValues,
fromValues,
}
25 changes: 25 additions & 0 deletions resolvers/analytic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const { Analytic } = require("../models/Analytic");

const { MESSAGE_RESPONSE } = require("../config/helpers");

module.exports = {
Query: {
events: async (root, args) => {
const events = await Analytic.find().lean({})

return events
},
},
Mutation: {
addLog: async (root, args, { id }) => {
if (!id) {
return MESSAGE_RESPONSE("TOKEN_REQ", "Analytic", false);
}

const { IP, customerId, event, from, data } = args;
const newLog = await Analytic.create(args)

return MESSAGE_RESPONSE("AddSuccess", "Log", true);
},
},
};