2023-12-24 10:21:40 -05:00
|
|
|
import DatabaseServer from '../components/DatabaseServer.js';
|
2024-03-20 20:31:50 -04:00
|
|
|
import {Model, DataTypes} from '@sequelize/core';
|
2023-12-24 10:21:40 -05:00
|
|
|
|
|
|
|
class youtubeChannels extends Model {
|
|
|
|
declare public ytchannel: string;
|
|
|
|
declare public dcchannel: string;
|
|
|
|
declare public dcrole: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export class YouTubeChannelsSvc {
|
|
|
|
private model: typeof youtubeChannels;
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
this.model = youtubeChannels;
|
|
|
|
this.model.init({
|
|
|
|
ytchannel: {
|
|
|
|
type: DataTypes.STRING,
|
|
|
|
allowNull: false,
|
|
|
|
primaryKey: true
|
|
|
|
},
|
|
|
|
dcchannel: {
|
|
|
|
type: DataTypes.STRING,
|
|
|
|
allowNull: false
|
|
|
|
},
|
|
|
|
dcrole: {
|
|
|
|
type: DataTypes.STRING,
|
|
|
|
allowNull: false
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
tableName: 'ytchannels',
|
|
|
|
createdAt: false,
|
|
|
|
updatedAt: false,
|
|
|
|
sequelize: DatabaseServer.seq
|
|
|
|
})
|
|
|
|
this.model.sync();
|
|
|
|
}
|
|
|
|
async addChannel(YTChannelID:string, DCChannelID:string, DCRole:string) {
|
2024-03-20 20:31:50 -04:00
|
|
|
const [_, created] = await this.model.findOrCreate({where: {ytchannel: YTChannelID}, defaults: {dcchannel: DCChannelID, dcrole: DCRole}});
|
|
|
|
return created;
|
2023-12-24 10:21:40 -05:00
|
|
|
}
|
2024-01-16 06:28:03 -05:00
|
|
|
delChannel = async(YTChannelID:string)=>await this.model.destroy({where: {ytchannel: YTChannelID}});
|
|
|
|
getChannels = async()=>await this.model.findAll();
|
2023-12-24 10:21:40 -05:00
|
|
|
}
|