Skip to content

Commit

Permalink
Add Site model.
Browse files Browse the repository at this point in the history
  • Loading branch information
mitkonikov committed Feb 9, 2024
1 parent 7283ff6 commit 4d0539a
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 0 deletions.
2 changes: 2 additions & 0 deletions backend/src/admin/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { files } from '../resources/files.js';
import { playlists } from '../resources/playlists.js';
import { thumbnails } from '../resources/thumbnail.js';
import { trailers } from '../resources/trailer.js';
import { sites } from '../resources/site.js';

import { componentLoader } from './component-loader.js';

Expand All @@ -23,6 +24,7 @@ const options: AdminJSOptions = {
playlists,
thumbnails,
trailers,
sites,
],
databases: [],
dashboard: {
Expand Down
2 changes: 2 additions & 0 deletions backend/src/models/playlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Document, Schema, model } from 'mongoose';
// Define Playlist interface
export interface IPlaylist extends Document {
name: string;
site: Schema.Types.ObjectId;
}

// Define playlist schema
Expand All @@ -12,6 +13,7 @@ export const playlistSchema = new Schema<IPlaylist>({
unique: true,
required: true,
},
site: { type: Schema.Types.ObjectId, ref: 'Site' },
});

const Playlist = model<IPlaylist>('Playlist', playlistSchema);
Expand Down
18 changes: 18 additions & 0 deletions backend/src/models/site.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Document, Schema, model } from 'mongoose';

// Define Site interface
export interface ISite extends Document {
name: string;
}

// Define site schema
export const siteSchema = new Schema<ISite>({
name: {
type: String,
unique: true,
required: true,
},
});

const Site = model<ISite>('Site', siteSchema);
export default Site;
4 changes: 4 additions & 0 deletions backend/src/resources/playlists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ export const playlists = {
name: {
type: 'string',
},
site: {
type: 'reference',
reference: 'Site',
},
},
},
};
12 changes: 12 additions & 0 deletions backend/src/resources/site.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Site from '../models/site.js';

export const sites = {
resource: Site,
options: {
properties: {
name: {
type: 'string',
},
},
},
};

0 comments on commit 4d0539a

Please sign in to comment.