-
-
Notifications
You must be signed in to change notification settings - Fork 2
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 #3 from austenstone/lots
Lots
- Loading branch information
Showing
25 changed files
with
512 additions
and
118 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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 |
---|---|---|
@@ -1 +1 @@ | ||
export * from './survery.controller'; | ||
export * from './survery.controller'; |
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,36 @@ | ||
import { Request, Response } from 'express'; | ||
import { Metrics, Breakdown } from '../models/metrics.model'; | ||
|
||
class MetricsController { | ||
// Get all metrics 📊 | ||
async getAllMetrics(req: Request, res: Response): Promise<void> { | ||
try { | ||
const metrics = await Metrics.findAll({ | ||
include: [Breakdown] | ||
}); | ||
res.status(200).json(metrics); // 🎉 All metrics retrieved! | ||
} catch (error) { | ||
res.status(500).json(error); // 🚨 Error handling | ||
} | ||
} | ||
|
||
// Get metrics by day 📅 | ||
async getMetricsByDay(req: Request, res: Response): Promise<void> { | ||
try { | ||
const { day } = req.params; | ||
const metrics = await Metrics.findOne({ | ||
where: { day }, | ||
include: [Breakdown] | ||
}); | ||
if (metrics) { | ||
res.status(200).json(metrics); // 🎉 Metrics found! | ||
} else { | ||
res.status(404).json({ error: 'Metrics not found' }); // 🚨 Metrics not found | ||
} | ||
} catch (error) { | ||
res.status(500).json(error); // 🚨 Error handling | ||
} | ||
} | ||
} | ||
|
||
export default new MetricsController(); |
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
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
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,96 @@ | ||
import { DataTypes } from 'sequelize'; | ||
import sequelize from '../database'; | ||
|
||
const Metrics = sequelize.define('Metrics', { | ||
day: { | ||
type: DataTypes.DATEONLY, | ||
primaryKey: true, | ||
allowNull: false, | ||
}, | ||
totalSuggestionsCount: { | ||
type: DataTypes.INTEGER, | ||
allowNull: false, | ||
}, | ||
totalAcceptancesCount: { | ||
type: DataTypes.INTEGER, | ||
allowNull: false, | ||
}, | ||
totalLinesSuggested: { | ||
type: DataTypes.INTEGER, | ||
allowNull: false, | ||
}, | ||
totalLinesAccepted: { | ||
type: DataTypes.INTEGER, | ||
allowNull: false, | ||
}, | ||
totalActiveUsers: { | ||
type: DataTypes.INTEGER, | ||
allowNull: false, | ||
}, | ||
totalChatAcceptances: { | ||
type: DataTypes.INTEGER, | ||
allowNull: false, | ||
}, | ||
totalChatTurns: { | ||
type: DataTypes.INTEGER, | ||
allowNull: false, | ||
}, | ||
totalActiveChatUsers: { | ||
type: DataTypes.INTEGER, | ||
allowNull: false, | ||
}, | ||
}, { | ||
tableName: 'metrics', | ||
timestamps: false, | ||
}); | ||
|
||
const Breakdown = sequelize.define('Breakdown', { | ||
id: { | ||
type: DataTypes.INTEGER, | ||
autoIncrement: true, | ||
primaryKey: true, | ||
}, | ||
metricsDay: { | ||
type: DataTypes.DATEONLY, | ||
references: { | ||
model: Metrics, | ||
key: 'day', | ||
}, | ||
}, | ||
language: { | ||
type: DataTypes.STRING, | ||
allowNull: false, | ||
}, | ||
editor: { | ||
type: DataTypes.STRING, | ||
allowNull: false, | ||
}, | ||
suggestionsCount: { | ||
type: DataTypes.INTEGER, | ||
allowNull: false, | ||
}, | ||
acceptancesCount: { | ||
type: DataTypes.INTEGER, | ||
allowNull: false, | ||
}, | ||
linesSuggested: { | ||
type: DataTypes.INTEGER, | ||
allowNull: false, | ||
}, | ||
linesAccepted: { | ||
type: DataTypes.INTEGER, | ||
allowNull: false, | ||
}, | ||
activeUsers: { | ||
type: DataTypes.INTEGER, | ||
allowNull: false, | ||
}, | ||
}, { | ||
tableName: 'breakdown', | ||
timestamps: false, | ||
}); | ||
|
||
Metrics.hasMany(Breakdown, { foreignKey: 'metricsDay' }); | ||
Breakdown.belongsTo(Metrics, { foreignKey: 'metricsDay' }); | ||
|
||
export { Metrics, Breakdown }; |
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
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
Oops, something went wrong.