monkeeShark/src/chart/hashtag.ts

57 lines
1 KiB
TypeScript
Raw Normal View History

2018-10-22 20:36:35 +00:00
import autobind from 'autobind-decorator';
import Chart, { Obj } from './';
import { IUser, isLocalUser } from '../models/user';
import db from '../db/mongodb';
2018-10-22 20:36:35 +00:00
/**
*
*/
type HashtagLog = {
local: {
/**
* 稿
*/
count: number;
};
remote: HashtagLog['local'];
2018-10-22 20:36:35 +00:00
};
class HashtagChart extends Chart<HashtagLog> {
constructor() {
super('hashtag', true);
// 後方互換性のため
db.get('chart.hashtag').findOne().then(doc => {
if (doc != null && doc.data.local == null) {
db.get('chart.hashtag').drop();
}
});
2018-10-22 20:36:35 +00:00
}
@autobind
protected async getTemplate(init: boolean, latest?: HashtagLog): Promise<HashtagLog> {
return {
local: {
count: 0
},
remote: {
count: 0
}
2018-10-22 20:36:35 +00:00
};
}
@autobind
public async update(hashtag: string, user: IUser) {
const update: Obj = {
2018-10-22 20:36:35 +00:00
count: 1
};
await this.incIfUnique({
[isLocalUser(user) ? 'local' : 'remote']: update
}, 'users', user._id.toHexString(), hashtag);
2018-10-22 20:36:35 +00:00
}
}
export default new HashtagChart();