feat: friendships
This commit is contained in:
parent
af1336e859
commit
e82c173939
|
@ -1,7 +1,14 @@
|
||||||
|
import {DataTypes as Types} from 'sequelize';
|
||||||
import BaseModel from './base';
|
import BaseModel from './base';
|
||||||
|
|
||||||
class Friendship extends BaseModel {
|
class Friendship extends BaseModel {
|
||||||
|
|
||||||
|
static get attributes() {
|
||||||
|
return {
|
||||||
|
state: Types.ENUM(['pending', 'active']),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
static associate({User}) {
|
static associate({User}) {
|
||||||
User.hasMany(this, {
|
User.hasMany(this, {
|
||||||
as: 'adder',
|
as: 'adder',
|
||||||
|
|
|
@ -44,7 +44,17 @@ class User extends BaseModel {
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
return friendships.map(({adderId, addeeId}) => (adderId === this.id ? addeeId : adderId));
|
return Promise.all(
|
||||||
|
friendships.map(async ({adderId, addeeId, state}) => {
|
||||||
|
const otherId = adderId === this.id ? addeeId : adderId;
|
||||||
|
const user = await User.findByPk(otherId);
|
||||||
|
return {
|
||||||
|
id: user.id,
|
||||||
|
redditUsername: user.redditUsername,
|
||||||
|
state,
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
validatePassword(plaintext) {
|
validatePassword(plaintext) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user