Worked on zone objects, tile tags and searching
This commit is contained in:
14
src/app/repositories/ObjectRepository.ts
Normal file
14
src/app/repositories/ObjectRepository.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import prisma from '../utilities/Prisma'; // Import the global Prisma instance
|
||||
import { Object } from '@prisma/client'
|
||||
|
||||
class ObjectRepository {
|
||||
getById(id: string): Promise<Object | null> {
|
||||
return prisma.object.findUnique({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default new ObjectRepository();
|
45
src/app/repositories/TileTagRepository.ts
Normal file
45
src/app/repositories/TileTagRepository.ts
Normal file
@ -0,0 +1,45 @@
|
||||
import prisma from '../utilities/Prisma'; // Import the global Prisma instance
|
||||
import { TileTag } from '@prisma/client'
|
||||
|
||||
class TileTagRepository {
|
||||
async upsertTileTag(tile: string, tags: string[]): Promise<TileTag> {
|
||||
return prisma.tileTag.upsert({
|
||||
where: { tile },
|
||||
create: {
|
||||
tile,
|
||||
tags: tags,
|
||||
},
|
||||
update: {
|
||||
tags: tags,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async getTileTag(tile: string): Promise<TileTag | null> {
|
||||
return prisma.tileTag.findUnique({
|
||||
where: { tile },
|
||||
});
|
||||
}
|
||||
|
||||
async deleteTileTag(tile: string): Promise<TileTag> {
|
||||
return prisma.tileTag.delete({
|
||||
where: { tile },
|
||||
});
|
||||
}
|
||||
|
||||
async searchTilesByTags(tags: string[]): Promise<TileTag[]> {
|
||||
return prisma.tileTag.findMany({
|
||||
where: {
|
||||
tags: {
|
||||
array_contains: tags,
|
||||
} as any, // Type assertion needed due to Json field
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async getAllTileTags(): Promise<TileTag[]> {
|
||||
return prisma.tileTag.findMany();
|
||||
}
|
||||
}
|
||||
|
||||
export default new TileTagRepository();
|
Reference in New Issue
Block a user