2019-06-22 18:52:24 +03:00
|
|
|
import { AllowedGuild } from "./entities/AllowedGuild";
|
|
|
|
import {
|
|
|
|
getConnection,
|
|
|
|
getRepository,
|
|
|
|
Repository,
|
|
|
|
Transaction,
|
|
|
|
TransactionManager,
|
|
|
|
TransactionRepository,
|
|
|
|
} from "typeorm";
|
|
|
|
import { BaseGuildRepository } from "./BaseGuildRepository";
|
|
|
|
import { BaseRepository } from "./BaseRepository";
|
|
|
|
|
|
|
|
export class AllowedGuilds extends BaseRepository {
|
|
|
|
private allowedGuilds: Repository<AllowedGuild>;
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.allowedGuilds = getRepository(AllowedGuild);
|
|
|
|
}
|
|
|
|
|
|
|
|
async isAllowed(guildId) {
|
|
|
|
const count = await this.allowedGuilds.count({
|
|
|
|
where: {
|
2019-06-23 19:18:41 +03:00
|
|
|
id: guildId,
|
2019-06-22 18:52:24 +03:00
|
|
|
},
|
|
|
|
});
|
|
|
|
return count !== 0;
|
|
|
|
}
|
|
|
|
|
2019-06-23 19:18:41 +03:00
|
|
|
getForApiUser(userId) {
|
2019-06-22 18:52:24 +03:00
|
|
|
return this.allowedGuilds
|
|
|
|
.createQueryBuilder("allowed_guilds")
|
|
|
|
.innerJoin(
|
2019-06-23 19:18:41 +03:00
|
|
|
"api_permissions",
|
|
|
|
"api_permissions",
|
|
|
|
"api_permissions.guild_id = allowed_guilds.id AND api_permissions.user_id = :userId",
|
2019-06-22 18:52:24 +03:00
|
|
|
{ userId },
|
|
|
|
)
|
|
|
|
.getMany();
|
|
|
|
}
|
2019-06-23 19:18:41 +03:00
|
|
|
|
2019-07-12 14:25:27 +03:00
|
|
|
updateInfo(id, name, icon, ownerId) {
|
|
|
|
return this.allowedGuilds.update({ id }, { name, icon, owner_id: ownerId });
|
2019-06-23 19:18:41 +03:00
|
|
|
}
|
2019-06-22 18:52:24 +03:00
|
|
|
}
|