Skip to content
Snippets Groups Projects
Commit e9347cd2 authored by Louis's avatar Louis :fire:
Browse files

Merge branch 'release/v1.3.0'

parents ab7a9faa 26f2dc74
No related branches found
No related tags found
No related merge requests found
module.exports = {
up: (migration, Types) => {
return migration.createTable('bundle_codes', {
id: {
type: Types.UUID,
primaryKey: true,
defaultValue: Types.UUIDV4,
allowNull: false,
},
name: {
type: Types.TEXT,
allowNull: false,
},
description: {
type: Types.TEXT,
allowNull: false,
},
platforms: {
type: Types.JSONB,
defaultValue: {},
allowNull: false,
},
meta: {
type: Types.JSONB,
defaultValue: {},
allowNull: false,
},
created_at: {
type: Types.DATE,
defaultValue: Types.fn('now'),
allowNull: false,
},
updated_at: {
type: Types.DATE,
defaultValue: Types.fn('now'),
allowNull: false,
},
deleted_at: {
type: Types.DATE,
defaultValue: null,
allowNull: true,
},
})
},
down: (migration, Types) => {
return migration.dropTable('')
},
}
\ No newline at end of file
module.exports = {
up: (migration, Types) => {
return migration.createTable('user_bundle_codes', {
user_id: {
type: Types.UUID,
primaryKey: true,
references: {
model: 'users',
key: 'id',
},
onDelete: 'cascade',
onUpdate: 'cascade',
},
bundle_code_id: {
type: Types.UUID,
primaryKey: true,
references: {
model: 'bundle_codes',
key: 'id',
},
onDelete: 'cascade',
onUpdate: 'cascade',
},
})
},
down: (migration, Types) => {
return migration.dropTable('user_bundle_codes')
},
}
\ No newline at end of file
{
"name": "jetsam-server",
"version": "1.2.0",
"version": "1.3.0",
"description": "",
"main": "index.js",
"scripts": {
......
const timestamps = require('./properties/timestamps')
module.exports = (sequelize, DataTypes) => {
const Model = sequelize.define('BundleCode', Object.assign(
{
id: {
type: DataTypes.UUID,
primaryKey: true,
defaultValue: DataTypes.UUIDV4,
validate: {
isUUID: 4,
},
},
name: {
type: DataTypes.TEXT,
},
description: {
type: DataTypes.TEXT,
},
platforms: {
type: DataTypes.JSONB,
},
meta: {
type: DataTypes.JSONB,
},
},
timestamps(DataTypes),
), {
paranoid: true,
tableName: 'bundle_codes',
})
Model.getPolyIdentifier = () => 'bundle_code'
Model.getRelationIdentifier = () => 'bundle_codes'
Model.prototype.toJSON = function userToJSON() {
return {
id: this.id,
name: this.name,
description: this.description,
platforms: this.platforms,
meta: this.meta,
created_at: this.created_at,
updated_at: this.updated_at,
}
}
Model.associate = function defineModelAssociations(models) {
Model.belongsToMany(models.User, { through: 'user_bundle_codes', foreignKey: 'bundle_code_id', otherKey: 'user_id', timestamps: false })
}
Model.relations = []
return Model
}
\ No newline at end of file
......@@ -142,6 +142,7 @@ module.exports = (sequelize, DataTypes) => {
Model.hasMany(models.RefreshToken, { foreignKey: 'user_id' })
Model.hasMany(models.File, { foreignKey: 'user_id' })
Model.belongsToMany(models.File, { as: 'likes', through: 'user_file_likes', foreignKey: 'user_id', otherKey: 'file_id' })
Model.belongsToMany(models.BundleCode, { through: 'user_bundle_codes', foreignKey: 'user_id', otherKey: 'bundle_code_id', timestamps: false })
}
Model.relations = [
......
......@@ -58,7 +58,9 @@ module.exports = class AuthService extends ContextualModule {
}
} else if (this.ctx.get('Authorization')) {
const token = this.ctx.get('Authorization').substr(BEARER_PREFIX.length)
console.log("TOKEN", token)
const user = await this.ctx.services.userService.findByAccessToken(token)
console.log(user)
if (user) {
this.authenticateAs(user)
return user
......
exports.getBundles = async ctx => {
const user = await ctx.services.authService.getUser()
if (user == null) {
ctx.body = {
bundles: [],
}
} else {
console.log(user.id)
const bundles = await user.getBundleCodes()
ctx.body = {
bundles,
}
}
}
\ No newline at end of file
......@@ -61,7 +61,7 @@ exports.triggerPasswordReset = async ctx => {
}
ctx.body = {
reset_token: token,
reset_token: null,
}
}
......
......@@ -50,6 +50,7 @@ function mount(api) {
api.post('/auth/reset-password', controller('api/auth', 'handlePasswordReset'))
api.get('/self', controller('api/user', 'self'))
api.get('/self/bundles', controller('api/app', 'getBundles'))
api.put('/self/:property', controller('api/user', 'updateOne'))
api.post('/feedback', controller('api/feedback', 'send'))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment