-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1351 from andrew-bierman/import-packTemplate
Create public end Point to import pack template
- Loading branch information
Showing
21 changed files
with
499 additions
and
339 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { addPackTemplateService } from '../../services/packTemplate/packTemplate.service'; | ||
import * as validator from '@packrat/validations'; | ||
import { publicProcedure } from '../../trpc'; | ||
|
||
export function importPackTemplatesRoute() { | ||
return publicProcedure | ||
.input(validator.addPackTemplates) | ||
.mutation(async (opts) => { | ||
const array = opts.input; | ||
const packTemplates = []; | ||
for (let idx = 0; idx < array.length; idx++) { | ||
const input = array[idx]; | ||
try { | ||
const packTemplate = await addPackTemplateService( | ||
input, | ||
opts.ctx.executionCtx, | ||
); | ||
packTemplates.push(packTemplate); | ||
} catch (error) { | ||
console.log(error); | ||
throw error; | ||
} | ||
} | ||
return packTemplates; | ||
}); | ||
} | ||
|
||
export function addPackTemplateRoute() { | ||
return publicProcedure | ||
.input(validator.addPackTemplate) | ||
.mutation(async (opts) => { | ||
const packTemplate = await addPackTemplateService( | ||
opts.input, | ||
opts.ctx.executionCtx, | ||
); | ||
return packTemplate; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './addPackTemplate'; | ||
export * from './getPackTemplates'; | ||
export * from './getPackTemplate' | ||
export * from './getPackTemplate'; | ||
export * from './createPackFromTemplate'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { DbClient } from '../../db/client'; | ||
import { eq, and } from 'drizzle-orm'; | ||
import { | ||
type InsertItemPackTemplate, | ||
itemPackTemplate as ItemPackTemplateTable, | ||
} from '../../db/schema'; | ||
|
||
export class ItemPackTemplate { | ||
async create(data: InsertItemPackTemplate) { | ||
try { | ||
const item = await DbClient.instance | ||
.insert(ItemPackTemplateTable) | ||
.values(data) | ||
.returning() | ||
.get(); | ||
|
||
return item; | ||
} catch (error) { | ||
throw new Error(`Failed to create item: ${error.message}`); | ||
} | ||
} | ||
|
||
async findByItemIdAndPackTemplateId({ | ||
itemId, | ||
packTemplateId, | ||
}: { | ||
itemId: string; | ||
packTemplateId: string; | ||
}) { | ||
const itemFilter = eq(ItemPackTemplateTable.itemId, itemId); | ||
const packFilter = eq(ItemPackTemplateTable.packTemplateId, packTemplateId); | ||
|
||
const filter = and(itemFilter, packFilter); | ||
|
||
return await DbClient.instance.query.itemPackTemplate.findFirst({ | ||
where: filter, | ||
}); | ||
} | ||
} |
Oops, something went wrong.