App.js 724 B

12345678910111213141516171819202122232425262728293031323334353637
  1. //@flow
  2. const sequelize = require("./sequelize");
  3. const Sequelize = require("sequelize");
  4. const randomatic = require("randomatic");
  5. const App = sequelize.define("app", {
  6. name: {
  7. type: Sequelize.STRING
  8. },
  9. auth: {
  10. type: Sequelize.STRING,
  11. defaultValue: "",
  12. unique: true,
  13. primaryKey: true
  14. },
  15. activated: {
  16. type: Sequelize.BOOLEAN,
  17. defaultValue: false
  18. }
  19. }, {
  20. hooks: {
  21. afterCreate: (app, options, fn) => {
  22. let authCode = [
  23. app.id,
  24. randomatic("A", 5),
  25. randomatic("0", 3),
  26. randomatic("Aa0", 20)
  27. ].join("-");
  28. return app.updateAttributes({
  29. auth: authCode
  30. });
  31. }
  32. }
  33. });
  34. module.exports = App;