Commit 250bc1a7 authored by Цой Данил's avatar Цой Данил 💬

#1 added models for artists and wrote method to get them

parent 6b6f0134
import mongoose from "mongoose";
import IArtist from "../interfaces/IArtist";
const Schema = mongoose.Schema
const ArtistSchema = new Schema<IArtist>({
name:{
type: String,
require: true
},
photo:{
type: String,
require: true
},
information:{
type: String,
require: true
}
})
export const Artist = mongoose.model<IArtist>('Artist', ArtistSchema)
\ No newline at end of file
import { EStatuses } from "../enum/EStatuses";
import IArtist from "../interfaces/IArtist";
import IResponse from "../interfaces/IResponse";
import { Artist } from "../models/Artist";
export class ArtistsService {
public getArtists = async(): Promise<IResponse<IArtist[] | null>> => {
try{
const data = await Artist.find()
const response: IResponse<IArtist[]> = {
status: EStatuses.SUCCESS,
result: data,
message: 'Artists found'
}
return response
} catch (err: unknown){
const error = err as Error
const response: IResponse<null> = {
status: EStatuses.FAILURE,
result: null,
message: error.message
}
return response
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment