'use strict';

const objectSorter = require('../helpers/objectSorter');
const moment = require('moment');

class UserFollowing {
	constructor(document, db, config) {
		if (document == null || db == null || config == null) {
			throw new Error('missing arguments');
		}

		this.document = document;
		this.db = db;
	}

	// TODO: 各種操作用メソッドの追加

	serialize() {
		const res = {};
		Object.assign(res, this.document);

		// createdAt
		res.createdAt = parseInt(moment(res._id.getTimestamp()).format('X'));

		// id
		res.id = res._id.toString();
		delete res._id;

		Object.keys(res).sort();

		return objectSorter(res);
	}

	// 最新の情報を取得して同期する
	async fetchAsync() {
		this.document = (await this.db.userFollowings.findByIdAsync(this.document._id)).document;
	}
}
module.exports = UserFollowing;

@@ -747,16 +747,436 @@
 ment;%0A%09%7D
+%0A%0A%09async removeAsync() %7B%0A%09%09await this.db.userFollowings.removeAsync(%7B_id: this.document._id%7D);%0A%09%09this.document = null;%0A%09%7D%0A%0A%09// static methods%0A%0A%09static async findBySrcDestAsync(source, destination, db, config) %7B%0A%09%09if (source == null %7C%7C destination == null %7C%7C db == null %7C%7C config == null) %7B%0A%09%09%09throw new Error('missing arguments');%0A%09%09%7D%0A%0A%09%09return db.userFollowings.findAsync(%7Bsource: source, destination: destination%7D);%0A%09%7D
 %0A%7D%0Amodul

add methods