App.ts 700 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import sequelize from "./sequelize";
  2. import Sequelize, { Model } from "sequelize";
  3. import randomatic from "randomatic";
  4. class App extends Model {
  5. id!: number;
  6. name!: string;
  7. auth!: string;
  8. activated!: boolean;
  9. }
  10. App.init({
  11. name: {
  12. type: Sequelize.STRING
  13. },
  14. auth: {
  15. type: Sequelize.STRING,
  16. defaultValue: "",
  17. unique: true
  18. },
  19. activated: {
  20. type: Sequelize.BOOLEAN,
  21. defaultValue: false
  22. }
  23. }, {
  24. sequelize,
  25. hooks: {
  26. afterCreate: (app, options) => {
  27. let authCode = [
  28. app.id,
  29. randomatic("A", 5),
  30. randomatic("0", 3),
  31. randomatic("Aa0", 20)
  32. ].join("-");
  33. app.auth = authCode;
  34. }
  35. }
  36. });
  37. export default App;