2019-08-18 07:41:33 +02:00
|
|
|
import $ from 'cafy';
|
|
|
|
import define from '../../define';
|
|
|
|
import { ApiError } from '../../error';
|
|
|
|
import { Users, UserProfiles } from '../../../../models';
|
|
|
|
import { ID } from '../../../../misc/cafy-id';
|
|
|
|
import { toPunyNullable } from '../../../../misc/convert-host';
|
|
|
|
|
|
|
|
export const meta = {
|
|
|
|
desc: {
|
2021-03-06 14:34:11 +01:00
|
|
|
'ja-JP': '指定したユーザーの部屋の情報を取得します。',
|
2019-08-18 07:41:33 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
tags: ['room'],
|
|
|
|
|
2020-02-15 13:33:32 +01:00
|
|
|
requireCredential: false as const,
|
2019-08-18 07:41:33 +02:00
|
|
|
|
|
|
|
params: {
|
|
|
|
userId: {
|
|
|
|
validator: $.optional.type(ID),
|
|
|
|
desc: {
|
|
|
|
'ja-JP': '対象のユーザーのID',
|
|
|
|
'en-US': 'Target user ID'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
username: {
|
|
|
|
validator: $.optional.str
|
|
|
|
},
|
|
|
|
|
|
|
|
host: {
|
|
|
|
validator: $.optional.nullable.str
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
errors: {
|
|
|
|
noSuchUser: {
|
|
|
|
message: 'No such user.',
|
|
|
|
code: 'NO_SUCH_USER',
|
|
|
|
id: '7ad3fa3e-5e12-42f0-b23a-f3d13f10ee4b'
|
|
|
|
}
|
2021-03-06 14:34:11 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
res: {
|
|
|
|
type: 'object' as const,
|
|
|
|
optional: false as const, nullable: false as const,
|
|
|
|
properties: {
|
|
|
|
roomType: {
|
|
|
|
type: 'string' as const,
|
|
|
|
optional: false as const, nullable: false as const,
|
|
|
|
enum: ['default', 'washitsu']
|
|
|
|
},
|
|
|
|
furnitures: {
|
|
|
|
type: 'array' as const,
|
|
|
|
optional: false as const, nullable: false as const,
|
|
|
|
items: {
|
|
|
|
type: 'object' as const,
|
|
|
|
optional: false as const, nullable: false as const,
|
|
|
|
properties: {
|
|
|
|
id: {
|
|
|
|
type: 'string' as const,
|
|
|
|
optional: false as const, nullable: false as const
|
|
|
|
},
|
|
|
|
type: {
|
|
|
|
type: 'string' as const,
|
|
|
|
optional: false as const, nullable: false as const
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
type: 'object' as const,
|
|
|
|
optional: true as const, nullable: false as const,
|
|
|
|
description: 'Properties vary depending on the furniture'
|
|
|
|
},
|
|
|
|
position: {
|
|
|
|
type: 'object' as const,
|
|
|
|
optional: false as const, nullable: false as const,
|
|
|
|
properties: {
|
|
|
|
x: {
|
|
|
|
type: 'number' as const,
|
|
|
|
optional: false as const, nullable: false as const
|
|
|
|
},
|
|
|
|
y: {
|
|
|
|
type: 'number' as const,
|
|
|
|
optional: false as const, nullable: false as const
|
|
|
|
},
|
|
|
|
z: {
|
|
|
|
type: 'number' as const,
|
|
|
|
optional: false as const, nullable: false as const
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
rotation: {
|
|
|
|
type: 'object' as const,
|
|
|
|
optional: false as const, nullable: false as const,
|
|
|
|
properties: {
|
|
|
|
x: {
|
|
|
|
type: 'number' as const,
|
|
|
|
optional: false as const, nullable: false as const
|
|
|
|
},
|
|
|
|
y: {
|
|
|
|
type: 'number' as const,
|
|
|
|
optional: false as const, nullable: false as const
|
|
|
|
},
|
|
|
|
z: {
|
|
|
|
type: 'number' as const,
|
|
|
|
optional: false as const, nullable: false as const
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
carpetColor: {
|
|
|
|
type: 'string' as const,
|
|
|
|
optional: false as const, nullable: false as const,
|
|
|
|
format: 'hex',
|
|
|
|
example: '#85CAF0'
|
|
|
|
}
|
|
|
|
}
|
2019-08-18 07:41:33 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export default define(meta, async (ps, me) => {
|
|
|
|
const user = await Users.findOne(ps.userId != null
|
|
|
|
? { id: ps.userId }
|
|
|
|
: { usernameLower: ps.username!.toLowerCase(), host: toPunyNullable(ps.host) });
|
|
|
|
|
|
|
|
if (user == null) {
|
|
|
|
throw new ApiError(meta.errors.noSuchUser);
|
|
|
|
}
|
|
|
|
|
2021-02-13 07:33:38 +01:00
|
|
|
const profile = await UserProfiles.findOneOrFail(user.id);
|
2019-08-18 07:41:33 +02:00
|
|
|
|
|
|
|
if (profile.room.furnitures == null) {
|
2020-01-31 23:16:52 +01:00
|
|
|
await UserProfiles.update(user.id, {
|
2019-08-18 07:41:33 +02:00
|
|
|
room: {
|
|
|
|
furnitures: [],
|
|
|
|
...profile.room
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
profile.room.furnitures = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (profile.room.roomType == null) {
|
|
|
|
const initialType = 'default';
|
2020-01-31 23:16:52 +01:00
|
|
|
await UserProfiles.update(user.id, {
|
2019-08-18 07:41:33 +02:00
|
|
|
room: {
|
|
|
|
roomType: initialType as any,
|
|
|
|
...profile.room
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
profile.room.roomType = initialType;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (profile.room.carpetColor == null) {
|
|
|
|
const initialColor = '#85CAF0';
|
2020-01-31 23:16:52 +01:00
|
|
|
await UserProfiles.update(user.id, {
|
2019-08-18 07:41:33 +02:00
|
|
|
room: {
|
|
|
|
carpetColor: initialColor as any,
|
|
|
|
...profile.room
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
profile.room.carpetColor = initialColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
return profile.room;
|
|
|
|
});
|